You are on page 1of 34

National Institute of Electronics & Information Technology

Gorakhpur Center
Ministry of Electronics & Information Technology (MeitY), Government of India

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Contents to be covered
• Introduction of Programming
• Algorithms
• Flow-charts
• Programming Languages
• Compilation, Linking and Loading

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Programming Language
Problem oriented languages or high languages :
Examples of languages falling in this category are FORTRAN, BASIC, Pascal, etc. These
languages have been designed to give a better programming efficiency, faster program
development. Generally these languages have better programming capability but they
are less capable to deal with hardware or Hardware related programming.

Machine oriented languages or Low Level Languages :


Examples of languages falling in this category are Assembly language and Machine
Language. This languages have been designed to give a better machine efficiency i.e.
faster program execution. Generally these languages have better hardware
programming capability but it is very difficult and tedious to do create complex
application like and business application or some commercial application

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Programming Language Contd..
C as Middle Level Language :
C stands in between these two categories. That’s why it is called a Middle Level
Language, since it was designed to have both; a relatively good programming efficiency
(as compared to Machine Oriented Language) and a relatively good machine efficiency
(as compared to Problem Oriented Language).

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


C Language
• C language is a general purpose and structured programming language
developed by 'Dennis Ritchie' at AT &T's Bell Laboratories in the 1972
in USA.
• It is also called as 'Procedure oriented programming language.
• C is not specially designed for specific applications areas like COBOL
(Common Business-Oriented Language) or FORTRAN (Formula
Translation).
• It is well suited for business and scientific applications.
• It has some various features like control structures, looping statements,
arrays, macros required for these applications.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Introduction Contd..
• The C language has following numerous features as:
• Flexibility
• Portability
• Compactness
• Reusability

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Introduction Contd..
• FLEXIBLILITY: C is a powerful and flexible language. C is used for
projects as diverse as operating system, word processor, graphics,
spreadsheets and even compilers for other language. C is a popular
language preferred by professional programmers. As a result, a wide
variety of C compilers and helpful accessories are available.

• PORTABILITY: C is a portable language. Portable means that a C


program written for one computer system can be run on another
system with little or no modification. Portability is enhanced by the
ANSI standard by C, the set of rules for C compilers.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Introduction Contd..
• COMPACTNESS: C is a language of few words, containing only a
handful terms, called keywords, which serve as the base on which the
language’s functionality is built. You might think that a language with
more keyword would be more powerful. This isn’t true. As you will
find that it can be programmed to do any task.

• REUSABILITY: C is modular, C code can and should be written in


routine called functions. These functions can be reused in other
applications or programs. By passing pieces of information to the
function, you can create useful, reusable code.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


History of C
 C was evolved from ALGOL, BCPL and B.
 C was developed by Dennis Ritchie at the Bell Laboratories in 1972.
 Added new features and concepts like “data types”.
 It was developed along with the UNIX operating system.
 It was strongly integrated with the UNIX operating system.
 In 1983 American National Standards Institute (ANSI) appointed a
technical committee to define a standard for C. The committee
approved a version of C in December 1989 which is now known as
ANSI C.
 In 1990 International Standards Organization (ISO) has approved C
and this version of C is referred to as C89.
http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia
Importance of C
 Rich set of built-in functions
 Operators can be used to write any complex program.
 The C compiler combines the capabilities of an assembly language with the
features of a high-level language.
 It is well sited for writing both system software and business packages.
 Due to variety of data types and powerful operators programs written in C
are efficient and fast.
 There are only 32 keywords in C and its strength lies in its built in functions.
 C is highly portable and Ability to extend itself.
 C is a Structured Programming Language (requiring the user to think of a
problems in terms of function modules or blocks).

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Algorithm
Algorithm is a step-by-step procedure, which defines a set of instructions
to be executed in a certain order to get the desired output. Algorithms
are generally created independent of underlying languages, i.e. an
algorithm can be implemented in more than one programming language.

How to Write an Algorithm?


There are no well-defined standards for writing algorithms. Rather, it is
problem and resource dependent. Algorithms are never written to
support a particular programming code.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Algorithm Contd..
As we know that all programming languages share basic code constructs
like loops (do, for, while), flow-control (if-else), etc. These common
constructs can be used to write an algorithm.

We write algorithms in a step-by-step manner, but it is not always the


case. Algorithm writing is a process and is executed after the problem
domain is well-defined. That is, we should know the problem domain, for
which we are designing a solution.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Example of Algorithm
Problem: Design an algorithm to add two numbers and display the result.

Step 1 START
Step 2 declare three integers a, b & c
Step 3 define values of a & b
Step 4 add values of a & b
Step 5 store output of step 4 to c
Step 6 print c
Step 7 STOP

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Flow Chart
A flowchart is a graphical representation of decisions and their results mapped
out in individual shapes that were first developed by Herman Goldstine and
John von Neumann in the 1940’s. Flowcharts can provide a step-by-step
diagram for mapping out complex situations, such as programming code or
troubleshooting problems with a Computer.

A diagrammatic representation that illustrates the sequence of operations to


be performed to get the solution of a problem.
Generally drawn in the early stages of formulating computer solutions.
Facilitate communication between programmers and business people/end
users.
Once the flowchart is drawn, it becomes easy to write the program in any
high level language.
Must for the better documentation of a complex program.
http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia
Flow Chart

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Flow Chart START
Example 1: Draw a flow chart to show the
addition of two no.
Accept no1 & no1

Sum=no1+no2

Display the sum

STOP

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Flow Chart
Example 2: Draw a flowchart to find
the sum of first 50 natural numbers

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Flow Chart
Example 3: Draw a flowchart to find the largest of three numbers A,B & C.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Flow Chart
Example 4: Draw a flowchart to find
the factorial value of given number.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Advantages of using Flow Chart
 Communication: Flowcharts are better way of communicating the logic of a system
to all concerned.
 Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way.
 Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes.
 Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.
 Proper Debugging: The flowchart helps in debugging process.
 Efficient Program Maintenance: The maintenance of operating program becomes
easy with the help of flowchart. It helps the programmer to put efforts more
efficiently on that part.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Limitation of using Flow Chart
 Complex logic: Sometimes, the program logic is quite complicated.
 Alterations and Modifications: Alterations may require re-drawing completely.
 Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Basic Structure of C
C program can be viewed as group of building blocks called functions. A function is a
subroutine that may include one or more statement designed to perform a specific task. A
C program may contain one or more section as shown below :
Documentation Section
• Link Section
• Definition Section
• Global declaration Section
• main( ) function section
{
Declaration Part
Executable Part
}
Subprogram Section
Function1 ( )
{
}
Function2 ( )
{
}
http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia
Basic Structure of C Contd..

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Basic Structure of C Contd..
 Definition Section:
• This section defines all the symbolic constants. For example PI=3.14. By
defining symbolic constant one can use these symbolic constant instead
of constant value.
# define PI 3.14
# define Temp 35

 Global Declaration Section :


• This section contains the declaration of variables which are used by more
then more then one function of the program.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Basic Structure of C Contd..
 Main Function Section :
• A main() function is a heart of any ‘C’ language program. Any C program
is made up of 1 or more than 1 function. If there is only 1 function in the
program then it must be the main program. An execution of any C
program starts with main() function.

 Subprogram Or Sub Function Section :


• They are the code section which are define outside the boundary of main
function. This function can be called from any point or anywhere from
the program. Generally they are define to solve some frequent tasks.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Execution of C Program
C program executes in following 4 (four steps).

1. Creating a program:
An editor like notepad or WordPad is used to create a C program. This file
contains a source code which consists of executable code. The file should
be saved as '*.c' extension only.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Execution of C Program Contd..
2. Compiling the program:
The next step is to compile the program. The code is compiled by using
compiler. Compiler converts executable code to binary code i.e. object code.

3. Linking a program to library:


The object code of a program is linked with libraries that are needed for
execution of a program. The linker is used to link the program with libraries.
It creates a file with '*.exe' extension.

4. Execution of program:
The final executable file is then run by dos command prompt or by any other
software.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Quiz
Time

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Quiz
Time

1. C language has been developed by ____________.


a) Dennis Ritchie b) Charles Babbage
c) Dr. Grace Murray Hopper d) John McCarthy

2. All keywords in C are in ____________.


a) Lower Case letters b) Upper Case letters
c) Title Case letters d) None of the mentioned

3. Which of the following is not a valid variable name declaration?


a) int _a3 b) int a_3
c) int 3_a d) int _3a

4. Which of the following language is the predecessor to C Programming Language?


a) A b) B
c) BCPL d) C++
http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia
Quiz
Time

5. C was developed in the year ___


a) 1970 b) 1972
c) 1976 d) 1980

6. C is a ___ language
a) High Level b) Low Level
c) Middle Level d) Machine Level

7. C language is available for which of the following Operating Systems?


a) DOS b) Windows
c) Unix d) All of these

8. Which symbol is used as a statement terminator in C?


a) ! b) #
c) ~ d) ;
http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia
Quiz
Time

9. _____ is a picture in which the flows of computational paths are depicted.


a) Algorithm b) Program
c) Code d) Flow chart

10. C Language developed at _________?


a) AT & T's Bell Lab of USA in 1972 b) AT & T's Bell Lab of USA in 1970
c) Sun Microsystems in 1973 d) Cambridge University in 1972

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Assignments
 Installation of C Compiler.
 Program to print "Hello world"
 Program to print the value of a variable x=5.

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


References

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia


Thank You
Any Query

http://www.nielit.gov.in/gorakhpur /GKP.NIELIT @GKP_NIELIT /NIELITIndia /school/NIELITIndia

You might also like