BASICS OF C
Session 1
OBJECTIVES
• Differentiate between command, Program, and Software
• Explain the beginning of C
• Explain when and why C is used
• Discuss the c program structure
• Discuss Algorithm
• Draw Flowcharts
• List the symbol used in flowcharts
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
2
COMMAND, PROGRAM AND SOFTWARE
• In computing, a command is a directive to a computer program acting as an
interpreter of some kind, in order to perform a specific task.
• A program is a set of instructions(commands) written in computer language to
provide solution for a particular problem using computing devices is commonly
referred as Program.
• software is a collection of individual programs well packaged to run on a computer.
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
3
COMMAND, PROGRAM AND SOFTWARE
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
4
Software
Program Program
Command Command Command Command
BEGINNING OF C
• C programming language was invented by
Dennis Ritchie at the Bell Laboratories in 1972.
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
5
APPLICATION AREAS OF C PROGRAMMING
• C was initially used for Systems programming
• A System programs forms a portion of the operating system of the computer or it
support utilities
• Operating systems, Interpreters, Editors, Assembly programs are usually called
system programs
• The UNIX operating system was developed using C
• There are C compilers are available for almost all types of PC’s
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
6
MIDDLE LEVEL LANGUAGE
C is called middle-level language because it is actually bind the gap between a
machine level language and high-level languages. User can use c language to do
System Programming (for writing operating system) as well as Application
Programming (for generate menu driven customer billing system ).
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
7
STRUCTURED LANGUAGE
• C is called a structured programming language because to solve a large problem
• C allows compartmentalization of code and data
• C programming language divides the problem into smaller modules called
functions or procedures each of which handles a particular responsibility
• The program which solves the entire problem is a collection of such functions
For Ex: We have to develop a calculator . So we must have to divide programs into
functions of Addition, Subtraction, Multiplication, Division etc.
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
8
ABOUT C PROGRAMMING (keywords)
• There are 32 Keywords in C
• Keywords are those words whose meaning is already defined by Compiler
• Keywords cannot be used as a variable or function name
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
9
C PROGRAMMING STRUCTURE [ main() ]
 C programs are divided into units called functions
 Identify the start of program
 Every C program has a main ()
 Main() is a keyword , we must not used it for any other variable
 4 common ways of main declaration
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
10
C PROGRAMMING STRUCTURE[Delimiters]
• A delimiter is one or more characters that separates text strings
• Common delimiters are commas (,), semicolon (;), quotes ( ", ' ), braces ({}), pipes (|),
or slashes ( /  )
• C programming Delimiters are as follows
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
11
Delimiter Symbol Use
Colon : Useful for label
Semicolon ; Terminates statements
Parenthesis () Used in expression and function
Square brackets [] Used for array declaration
Curly braces {} Scope of statement
Hash # Preprocessor directive
Comma , variable separator
#include<stdio.h>
void main()
{
int a,b,c[10];
printf("hi");
}
C PROGRAMMING STRUCTURE[Comment]
• In computer programming, a comment is a programmer-readable explanation or
annotation in the source code of a computer program.
• They are added with the purpose of making the source code easier for humans to
understand, and are generally ignored by compilers and interpreters.
• In C Comment begin with /* and are terminated with */
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
12
THE C LIBRARY
• All C compilers come with a standard library of functions
• A function written by a programmer can be placed in the library and used
when required
• Some compilers allow functions to be added in the standard library
• Some compilers require a separate library to be created
• C Standard library functions or simply C Library functions are
inbuilt functions in C programming.
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
13
COMPILING AND RUNNING A PROGRAM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
14
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
What is algorithm ?
Algorithm is a set of instruction performed by programmer to solve a problems
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
15
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
16
3. Process the information
1. Understand the problem
clearly
4. Arrive the solution
2. Understand the problem
clearly
To solve problems
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
17
• Pseudocode is a simple way of writing programming code in English.
• Pseudocode is not actual programming language.
• For Example:
1. Start Program
2. Enter two numbers, A, B
3. Add the numbers together
4. Print Sum
5. End Program
Each pseudocode starts with a BEGIN/START To show some value ,
the word DISPLAY/PRINT is used The pseudocode finishes with an END
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
18
• What is Flowchart ?
Flowchart is a diagrammatic representation of an algorithm. Flowchart are very helpful
in writing program and explaining program to others.
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
19
• Flowchart Symbol
Different symbols are used for different states in flowchart, For example: Input /
Output and decision making has different symbols. The table below describes all the
symbols that are used in making flowchart
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
20
• Flowchart to add two numbers?
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
21
• Flowchart with If Construct
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
22
• Flowchart with If Else
PROGRAMMING APPROACH FOR SOLVING A PROBLEM
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
23
• Flowchart with For Loop
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
24

C programming Tutorial Session 1

  • 1.
  • 2.
    OBJECTIVES • Differentiate betweencommand, Program, and Software • Explain the beginning of C • Explain when and why C is used • Discuss the c program structure • Discuss Algorithm • Draw Flowcharts • List the symbol used in flowcharts Presented by: Muhammad Ehtisham Siddiqui (BSCS) 2
  • 3.
    COMMAND, PROGRAM ANDSOFTWARE • In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. • A program is a set of instructions(commands) written in computer language to provide solution for a particular problem using computing devices is commonly referred as Program. • software is a collection of individual programs well packaged to run on a computer. Presented by: Muhammad Ehtisham Siddiqui (BSCS) 3
  • 4.
    COMMAND, PROGRAM ANDSOFTWARE Presented by: Muhammad Ehtisham Siddiqui (BSCS) 4 Software Program Program Command Command Command Command
  • 5.
    BEGINNING OF C •C programming language was invented by Dennis Ritchie at the Bell Laboratories in 1972. Presented by: Muhammad Ehtisham Siddiqui (BSCS) 5
  • 6.
    APPLICATION AREAS OFC PROGRAMMING • C was initially used for Systems programming • A System programs forms a portion of the operating system of the computer or it support utilities • Operating systems, Interpreters, Editors, Assembly programs are usually called system programs • The UNIX operating system was developed using C • There are C compilers are available for almost all types of PC’s Presented by: Muhammad Ehtisham Siddiqui (BSCS) 6
  • 7.
    MIDDLE LEVEL LANGUAGE Cis called middle-level language because it is actually bind the gap between a machine level language and high-level languages. User can use c language to do System Programming (for writing operating system) as well as Application Programming (for generate menu driven customer billing system ). Presented by: Muhammad Ehtisham Siddiqui (BSCS) 7
  • 8.
    STRUCTURED LANGUAGE • Cis called a structured programming language because to solve a large problem • C allows compartmentalization of code and data • C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility • The program which solves the entire problem is a collection of such functions For Ex: We have to develop a calculator . So we must have to divide programs into functions of Addition, Subtraction, Multiplication, Division etc. Presented by: Muhammad Ehtisham Siddiqui (BSCS) 8
  • 9.
    ABOUT C PROGRAMMING(keywords) • There are 32 Keywords in C • Keywords are those words whose meaning is already defined by Compiler • Keywords cannot be used as a variable or function name Presented by: Muhammad Ehtisham Siddiqui (BSCS) 9
  • 10.
    C PROGRAMMING STRUCTURE[ main() ]  C programs are divided into units called functions  Identify the start of program  Every C program has a main ()  Main() is a keyword , we must not used it for any other variable  4 common ways of main declaration Presented by: Muhammad Ehtisham Siddiqui (BSCS) 10
  • 11.
    C PROGRAMMING STRUCTURE[Delimiters] •A delimiter is one or more characters that separates text strings • Common delimiters are commas (,), semicolon (;), quotes ( ", ' ), braces ({}), pipes (|), or slashes ( / ) • C programming Delimiters are as follows Presented by: Muhammad Ehtisham Siddiqui (BSCS) 11 Delimiter Symbol Use Colon : Useful for label Semicolon ; Terminates statements Parenthesis () Used in expression and function Square brackets [] Used for array declaration Curly braces {} Scope of statement Hash # Preprocessor directive Comma , variable separator #include<stdio.h> void main() { int a,b,c[10]; printf("hi"); }
  • 12.
    C PROGRAMMING STRUCTURE[Comment] •In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. • They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. • In C Comment begin with /* and are terminated with */ Presented by: Muhammad Ehtisham Siddiqui (BSCS) 12
  • 13.
    THE C LIBRARY •All C compilers come with a standard library of functions • A function written by a programmer can be placed in the library and used when required • Some compilers allow functions to be added in the standard library • Some compilers require a separate library to be created • C Standard library functions or simply C Library functions are inbuilt functions in C programming. Presented by: Muhammad Ehtisham Siddiqui (BSCS) 13
  • 14.
    COMPILING AND RUNNINGA PROGRAM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 14
  • 15.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM What is algorithm ? Algorithm is a set of instruction performed by programmer to solve a problems Presented by: Muhammad Ehtisham Siddiqui (BSCS) 15
  • 16.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 16 3. Process the information 1. Understand the problem clearly 4. Arrive the solution 2. Understand the problem clearly To solve problems
  • 17.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 17 • Pseudocode is a simple way of writing programming code in English. • Pseudocode is not actual programming language. • For Example: 1. Start Program 2. Enter two numbers, A, B 3. Add the numbers together 4. Print Sum 5. End Program Each pseudocode starts with a BEGIN/START To show some value , the word DISPLAY/PRINT is used The pseudocode finishes with an END
  • 18.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 18 • What is Flowchart ? Flowchart is a diagrammatic representation of an algorithm. Flowchart are very helpful in writing program and explaining program to others.
  • 19.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 19 • Flowchart Symbol Different symbols are used for different states in flowchart, For example: Input / Output and decision making has different symbols. The table below describes all the symbols that are used in making flowchart
  • 20.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 20 • Flowchart to add two numbers?
  • 21.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 21 • Flowchart with If Construct
  • 22.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 22 • Flowchart with If Else
  • 23.
    PROGRAMMING APPROACH FORSOLVING A PROBLEM Presented by: Muhammad Ehtisham Siddiqui (BSCS) 23 • Flowchart with For Loop
  • 24.
    Presented by: MuhammadEhtisham Siddiqui (BSCS) 24