KEMBAR78
1_Introduction of programming language C.pptx
Programming For Problem Solving
Lecture Number :- 1
“Introduction toC”
1
2
Learning Objectives
 Introduction
 Uses of C Programming
 Structure of a C Program
 Common used files in C
 Compiling and Executing process C Program
 Data Types
 Input and Output statements
3
INTRODUCTION
 C is one of the most popular programming language .
 C programming language was developed by Dennis Ritchie at
Bell Laboratories in 1970 by the UNIX Operating system.
 At initially C was designed for implementing System software
later it was widely used developing Application software.
 It is called middle level language because it reduces the gap
b/w High level language and Low level language.
4
CHARACTERISTIC OF
C
Its popularity as a programming language as follows:
 Modularity
 Structured
 Middle Level Language
 Case Sensitive
 Free Form
 Extensibility
 Portability
 Flexibility
 Core Language
5
USES OF C PROGRAMMING
 It is primarily used for System software (Ex. Operating
system ) and Embedded System application.
 C Language widely accepted by the Professional groups and
researcher due to most of the libraries, compiler and interpreter
of other programming are implemented in C.
 Due to Portability and convenience, C is also used as
intermediate language for implementing other languages.
 C is widely used in end user application.
STRUCTURE OF C PROGRAM
 C Program has Different Sections:
#include<stdio.h> Preprocessor Directives
Global Declaration
Function main
void main( )
{
Local Declaration
Statements;
}
function 1( )
{
Local Declaration
Statements;
}
Declaration Section
User defined Function
6
THE FIRST C PROGRAM
To write a C program look like:
Method-I
#include<stdio.h
>
#include<conio.
h> void main( )
{
printf(“Welcome
to the first C
program”);
getch();
}
Method-II
#include<stdio.h>
#include<conio.h>
int main( )
{
printf(“Welcome to
the first C
program”);
getch();
return (0);
}
Output:
Welcome to the first C
Program
Output:
Welcome to the first C Program
7
EXAMPLE OF C PROGRAM
Example:-1
#include<stdio.
h>
#include<conio.
h> void main( )
{
printf(“Welcome to the first C
program”); printf(“Hello World”);
getch();
}
Example:-2
#include<stdio.h>
#include<conio.h>
int main( )
{
printf(“Welcome to the first C programn”);
printf(“Hello World”);
getch();
return (0);
}
Output
:
Welcome to the first C program
Hello World
Output:
Welcome to the first C programHello
World
Note:- ‘n’ is an escape sequence and represents a newline character.
8
9
COMMON USED FILES IN C
Every C Program has four kinds of files these are:
 Source File (Extension .c or .cpp)
Header File (Extension .h)
Object File (Extension .O or .obj)
Executable File (Extension .exe )
COMPILING AND EXECUTING
PROCESS
Source File
(.c)
Compiler Linker
Object File
(.o or .obj)
Library File
(.h )
Executable
File
(.exe)
10
11
COMPILING AND EXECUTING
PROCESS
Assuming that you are using a Turbo C or Turbo C++ compiler here are the steps that
you need to follow to Compile and Execute your first C program…
 Start the compiler at C > prompt. The compiler (TC.EXE is usually
present in C:TCBIN directory).
 Select New from the File menu.
 Type the program.
 Save the program using F2 under a proper name (say Program1.c).
 Use Ctrl + F9 to Compile and Execute the program.
 Use Alt + F5 to view the output on the screen(Monitor).
12
DATA TYPES
 Basic Data Types:
 Derived Data Types: Array, function, pointer and
string.
 User Defined Data Types: Structure, union and enum.
Data Type Keyword
Used
Size in
bytes
Format
Specifier
Use
Character char 1 %c To store character
type data.
Integer int 2 %d To store integer data.
Floating
point
float 4 %f To store floating
point number.
Double double 8 %lf To store big floating point
number.
Valueless void 0 - To use in functions.
13
INPUT AND OUTPUT STATEMENTS
 Input data to the program from the standard input
device is called keyboard or mouse.
 Output produced by the program to a standard output device is
called monitor.
 These functions are defined in standard library is
called
stdio.h (standard input/output header file).
14
INPUT FUNCTION
 scanf ( ): Reads input data from the standard input device.
Syntax of scanf( ) function in c program.
scanf(“Format_specifier”, Address_list);
 Format_specifier decides the type of values that need to be provided to
the variable and these format specifiers are preceded by a % (is called
percentage) sign.
 Address_list determines the address of memory locations where the input
variable should be stored and sign & (is called ampersand) is used before
the name of variable..
15
INPUT
FUNCTION(Cont.)
Example of scanf( ) function
 scanf(“%d”, &a); // To read a single variable a is integer
 scanf(“%d%d”, &a, &b); // Multiple variables a and b integer
 scanf(“%d%c”, &a, &b); // Multiple variables a is integer and b is
character
 scanf(“%f%d”, &a, &b); // Multiple variables a is float and b is
integer
 scanf(“%f%c”, &a, &b); // Multiple variables a is float and b is character
scanf(“%f%f”, &a, &b); // Multiple variables a and b are float type
 Note: Ampersand(&) symbol followed by the input variable.
16
OUTPUT FUNCTION
 printf( ): Display output data on the screen (monitor).
Syntax of printf( ) function in c program.
printf(“Format_specifier”, Variables_list);
 Format_specifier decides the type of values that need to
be provided to the variable and these format specifiers
are preceded by a % (is called percentage) sign.
 Variables_list represents the name of variables where
the input data should be stored.
17
OUTPUT FUNCTION(Cont.)
Let’s see some examples of printf( ) function:
 printf(“Hello world”);
 printf(“%d”,a);
 printf(“%d%d”, a, b);
 printf( “%d%c”, a, b);
 printf( “%f%d”, a, b);
 printf( “%f%f”, a, b);
 printf( “%f%c”, a, b);
// Display Hello world
// Display integer value of a
// Display integer values of a and b
// Display integer a and character b
// Display float a and integer b
// Display float a and float b
// Display float a and character b
 Note: Ampersand (&) symbol does not use by the output
variable name .
PROGRAMS
 The following programs help to more understand about
scanf( ) and printf ( ) functions.
Write a C program to calculate sum of two numbers.
Output:
30
#include<stdio.h>
#include<conio.h>
void main( )
{ int a, b, c;
a = 10;
b = 20;
c = a + b;
printf(“%d”, c);
getch();
}
18
PROGRAMS(Cont.)
Write a C program to calculate sum of two numbers
using input function scanf ( ).
Output: Enter a and b
10 20
30
#include<stdio.h>
#include<conio.h> void
main( )
{
int a, b, c;
printf( “Enter a and b”) ;
scanf(“%d%d”, &a,&b);
c = a + b;
printf(“%d”, c);
getch();
}
19
20
PRACTICE PROGRAMS
1. Write a C program to print your resume with following details
Personal like Name, Address, Email-id, Qualifications and Skills and
others.
2. Write a C program to calculate Simple interest.
3. Write a C program to calculate sum and average of three integer numbers
using scanf() function.
4. Write a C program to swap two numbers.
SYLLABUS
21
22
23
Thank You

1_Introduction of programming language C.pptx

  • 1.
    Programming For ProblemSolving Lecture Number :- 1 “Introduction toC” 1
  • 2.
    2 Learning Objectives  Introduction Uses of C Programming  Structure of a C Program  Common used files in C  Compiling and Executing process C Program  Data Types  Input and Output statements
  • 3.
    3 INTRODUCTION  C isone of the most popular programming language .  C programming language was developed by Dennis Ritchie at Bell Laboratories in 1970 by the UNIX Operating system.  At initially C was designed for implementing System software later it was widely used developing Application software.  It is called middle level language because it reduces the gap b/w High level language and Low level language.
  • 4.
    4 CHARACTERISTIC OF C Its popularityas a programming language as follows:  Modularity  Structured  Middle Level Language  Case Sensitive  Free Form  Extensibility  Portability  Flexibility  Core Language
  • 5.
    5 USES OF CPROGRAMMING  It is primarily used for System software (Ex. Operating system ) and Embedded System application.  C Language widely accepted by the Professional groups and researcher due to most of the libraries, compiler and interpreter of other programming are implemented in C.  Due to Portability and convenience, C is also used as intermediate language for implementing other languages.  C is widely used in end user application.
  • 6.
    STRUCTURE OF CPROGRAM  C Program has Different Sections: #include<stdio.h> Preprocessor Directives Global Declaration Function main void main( ) { Local Declaration Statements; } function 1( ) { Local Declaration Statements; } Declaration Section User defined Function 6
  • 7.
    THE FIRST CPROGRAM To write a C program look like: Method-I #include<stdio.h > #include<conio. h> void main( ) { printf(“Welcome to the first C program”); getch(); } Method-II #include<stdio.h> #include<conio.h> int main( ) { printf(“Welcome to the first C program”); getch(); return (0); } Output: Welcome to the first C Program Output: Welcome to the first C Program 7
  • 8.
    EXAMPLE OF CPROGRAM Example:-1 #include<stdio. h> #include<conio. h> void main( ) { printf(“Welcome to the first C program”); printf(“Hello World”); getch(); } Example:-2 #include<stdio.h> #include<conio.h> int main( ) { printf(“Welcome to the first C programn”); printf(“Hello World”); getch(); return (0); } Output : Welcome to the first C program Hello World Output: Welcome to the first C programHello World Note:- ‘n’ is an escape sequence and represents a newline character. 8
  • 9.
    9 COMMON USED FILESIN C Every C Program has four kinds of files these are:  Source File (Extension .c or .cpp) Header File (Extension .h) Object File (Extension .O or .obj) Executable File (Extension .exe )
  • 10.
    COMPILING AND EXECUTING PROCESS SourceFile (.c) Compiler Linker Object File (.o or .obj) Library File (.h ) Executable File (.exe) 10
  • 11.
    11 COMPILING AND EXECUTING PROCESS Assumingthat you are using a Turbo C or Turbo C++ compiler here are the steps that you need to follow to Compile and Execute your first C program…  Start the compiler at C > prompt. The compiler (TC.EXE is usually present in C:TCBIN directory).  Select New from the File menu.  Type the program.  Save the program using F2 under a proper name (say Program1.c).  Use Ctrl + F9 to Compile and Execute the program.  Use Alt + F5 to view the output on the screen(Monitor).
  • 12.
    12 DATA TYPES  BasicData Types:  Derived Data Types: Array, function, pointer and string.  User Defined Data Types: Structure, union and enum. Data Type Keyword Used Size in bytes Format Specifier Use Character char 1 %c To store character type data. Integer int 2 %d To store integer data. Floating point float 4 %f To store floating point number. Double double 8 %lf To store big floating point number. Valueless void 0 - To use in functions.
  • 13.
    13 INPUT AND OUTPUTSTATEMENTS  Input data to the program from the standard input device is called keyboard or mouse.  Output produced by the program to a standard output device is called monitor.  These functions are defined in standard library is called stdio.h (standard input/output header file).
  • 14.
    14 INPUT FUNCTION  scanf( ): Reads input data from the standard input device. Syntax of scanf( ) function in c program. scanf(“Format_specifier”, Address_list);  Format_specifier decides the type of values that need to be provided to the variable and these format specifiers are preceded by a % (is called percentage) sign.  Address_list determines the address of memory locations where the input variable should be stored and sign & (is called ampersand) is used before the name of variable..
  • 15.
    15 INPUT FUNCTION(Cont.) Example of scanf() function  scanf(“%d”, &a); // To read a single variable a is integer  scanf(“%d%d”, &a, &b); // Multiple variables a and b integer  scanf(“%d%c”, &a, &b); // Multiple variables a is integer and b is character  scanf(“%f%d”, &a, &b); // Multiple variables a is float and b is integer  scanf(“%f%c”, &a, &b); // Multiple variables a is float and b is character scanf(“%f%f”, &a, &b); // Multiple variables a and b are float type  Note: Ampersand(&) symbol followed by the input variable.
  • 16.
    16 OUTPUT FUNCTION  printf(): Display output data on the screen (monitor). Syntax of printf( ) function in c program. printf(“Format_specifier”, Variables_list);  Format_specifier decides the type of values that need to be provided to the variable and these format specifiers are preceded by a % (is called percentage) sign.  Variables_list represents the name of variables where the input data should be stored.
  • 17.
    17 OUTPUT FUNCTION(Cont.) Let’s seesome examples of printf( ) function:  printf(“Hello world”);  printf(“%d”,a);  printf(“%d%d”, a, b);  printf( “%d%c”, a, b);  printf( “%f%d”, a, b);  printf( “%f%f”, a, b);  printf( “%f%c”, a, b); // Display Hello world // Display integer value of a // Display integer values of a and b // Display integer a and character b // Display float a and integer b // Display float a and float b // Display float a and character b  Note: Ampersand (&) symbol does not use by the output variable name .
  • 18.
    PROGRAMS  The followingprograms help to more understand about scanf( ) and printf ( ) functions. Write a C program to calculate sum of two numbers. Output: 30 #include<stdio.h> #include<conio.h> void main( ) { int a, b, c; a = 10; b = 20; c = a + b; printf(“%d”, c); getch(); } 18
  • 19.
    PROGRAMS(Cont.) Write a Cprogram to calculate sum of two numbers using input function scanf ( ). Output: Enter a and b 10 20 30 #include<stdio.h> #include<conio.h> void main( ) { int a, b, c; printf( “Enter a and b”) ; scanf(“%d%d”, &a,&b); c = a + b; printf(“%d”, c); getch(); } 19
  • 20.
    20 PRACTICE PROGRAMS 1. Writea C program to print your resume with following details Personal like Name, Address, Email-id, Qualifications and Skills and others. 2. Write a C program to calculate Simple interest. 3. Write a C program to calculate sum and average of three integer numbers using scanf() function. 4. Write a C program to swap two numbers.
  • 21.
  • 22.
  • 23.