SlideShare a Scribd company logo
Day – 01
Problem Solving with Flow Charts &
Basics of C Programming
The following symbols are used to represent the Flow Charts
• Ellipse : To represent start or stop
• Parellagram : To represent input/output
• Rectangle : To represent the processing or calculations
• Rhambus : To represent the conditional
statements
• Small Circle : To use as a connector
• Arrows : For directions
1. Write an algorithm to calculate the addition of 2
numbers.
• start
• step 1: read a
• step 2: read b
• step 3: c := a+b
• step 4: print a
• step 5: print b
• step 6: print c
• stop
2. Draw the flow chart to calculate the addition of
2 numbers.
3. write an algorithm to calculate the addition of 3 numbers.
• start
• step 1: read a
• step 2: read b
• step 3: read c
• step 4: d := a+b+c
• step 5: print a
• step 6: print b
• step 7: print c
• step 8: print d
• stop
Rewrite the above the algorithm to represent
more input and output(read or print) statements
in a single line.
• start
• step 1: read a,b,c
• step 2: d := a+b+c
• step 3: print a,b,c,d
• stop
Draw the flow chart for addition of 3 numbers.
basics of c programming  for naiver.pptx
• Algorithm 3.
write an algorithm to calculate the total marks
and average marks of 3 subjects
(maths,physics and chemistry)
• start
• step 1: read maths,physics,chemistry
• step 2: total := maths+physics+chemistry
• step 3: avg := total/3
• step 4: print maths,physics,chemistry,total,avg
• stop
Draw the flow chart for the above algorithm
basics of c programming  for naiver.pptx
Algorithm 4.
write an algorithm to calculate the area of a circle.
• start
• step 1: read radius
• step 2: area_circle := 3.14 * radius * radius
• step 3: print radius,area_circle
• stop
Draw the flow chart for the above algorithm
basics of c programming  for naiver.pptx
Algorithm 7.
write an algorithm to find the biggest of two
numbers.
• start
• step 1: read num1,num2
• step 2: if num1 > num2 then
• print "num1 is big"
• else
• print "num2 is big"
• stop
Draw the flow chart for above algorithm
basics of c programming  for naiver.pptx
Algorithm 8.
write an algorithm to find the biggest of three
numbers.
• start
• step 1: read num1,num2,num3
• step 2: if num1 > num2 and num1 > num3 then
• print "num1 is big"
• else if num2 > num1 and num2 > num3 then
• print "num2 is big"
• else
• print "num3 is big"
• stop
Draw the flow chart for the above algorithm
basics of c programming  for naiver.pptx
Introduction to C Programming Language
• C Programming Language is Procedural
Programming Language
• It is developed by Dennis Ritchie in the year
1972
• It is developed as system programming
language to write operating systems and
compilers.
Features of C Programming Language:
• Low level access to memory
• rich set of keywords
• Alphabets, Digits and Symbols
• keywords
• statements
• programs
Alphabets :
a-z, A-Z
Digits :
• 0-9
Symbols :
• ~ tilde
• ! Exclamatory
• @ at the rate
• # Hash(preprocessor)
• $ Dollar
• % Percentage
• ^ carret
• & ampersand
• * star
• ( parenthesis open
• ) parenthesis close
• - highfun/minus
• _ underscore
• + plus
• = equal
• : colon
• ; semi colon
• " Double Quotes
• ' Single Quote
• < less than
• > greater than
• , comma
• . dot
• ? question mark
• / slash or division
•  backward slash
• | vertical bar
• { brace or curley brace open
• } brace or curley brace close
• [ bracket open
• ] bracket close
Keywords :
• Keywords are the reserved words in the
programming language.
• Each keyword in c language is having its own
specific purpose and meaning.
• These keywords are not used for any other
purpose.
• All the keywords are written in lower case
alphabets.
The following are the keywords of C language
• auto
• break
• case
• char
• const or constant
• continue
• default
• do
• double
• else
• enum
• extern
• float
• for
• goto
• if
• int
• long
• register
• return
• short
• signed
• sizeof
• static
• struct
• switch
• typedef
• union
• unsigned
• void
• volatile
• while
Structure of C Programming Language
basics of c programming  for naiver.pptx
Link/Header File Include Section:
• In this section we can include the header
libraries or we can link the other
• programs with the current programs
We can include the header library using the
preprocessor directive #includein the program
Here # symbol is known as a preprocessor and
#include is a preprocessor directive.
• Example :
• #include<stdio.h>
• here stdio.h is a standard input/output header
library.
• here .h indicates and header library/file.
Definition Section:
• Here, we define the macro's(constants) or
user defined function prototypes.
Global Variable Decleration Section:
• Here we declare the global variables required
in the program.
main function:
• main function is compulsory in all the c
programs.
• The program execution always begins from
the main function only.
(or)
• The starting point of C program execution is
from main only.
• We can write the main function as follows.
main()
{
}
: main followed by open parenthesis and closed
parenthesis then immediately continued with
open brace and closed brace.
• We cannot write anything between the closed
parenthesis and the open brace of main
function.
• In between the open brace and closed brace
of main function we write the decleration
section and execution section.
Decleration Section:
• In the decleration section we can declare the
variables required in the
• program.
• The first section of main function must be the
declreration section.
Execution Section:
• All the executable statements can be written
under the execution section.
• The executable statements like input, output
and calculation statements.
• The main function returns an integer value
always, Hence we must write a return
statement at the end of main function.
• We can write the return statement using the
keyword return.
example:
• return 0;
User defined functions:
• We can write zero or n number of user
defined functions in the C program.
Datatypes:
• A datatype specifies the compiler that a type
of value is stored in the variable.
Datatypes:
1. Predefined Datatypes/Basic Datatypes
i. integer types
- short int
- int
- long int
ii. real types
- float
- double
- long double
iii. charecter types
- char
2. Derived Datatypes
i. arrays
ii. strings
iii. functions
iv. pointers
3. User Defined Datatypes
i. structures
ii. unions
iii. enumerations
Datatypes sizes and range:
basics of c programming  for naiver.pptx
Identifier:
• An identifier is a name of variable, constant,
pointer, array, string, function, structure and
union.
Rules for defining the identifiers:
1. we can use all the lower case alphabets from a to
z, digits from 0 to 9 and only one symbol
underscore _ in defining the identifier name.
2. we can start with either any alphabet from lower
case a to z or _ symbol.
3. we cannot start with any digit.
4. we cannot give any white spaces(space,tab or
newline charecter) in the identifier name.
5. The length of an identifier will be from one
charecter to 36 charecters.
Ex:
• a
• student_name
• gross_salary
• _subject
• result_1
Variable:
• A variable is a named memory location to
store the values.
• We can declare the variables using the
datatype as follows.
syntax:
• datatype variablename;
ex:
• int num1;
• int num2;
• int num3;
(or)
• int num1,num2,num3;
• num1=10;
• num2=20;
• num3=num1+num2;
Input/Output functions:
• In C language the input/output functions are
available in the stdio.h(standard input/output
header library).
The input/output functions are classified into 2
categories.
• 1. Formatted Input/Output Functions
• 2. Unformatted Input/Output Functions
1. Formatted Input/Output Functions:
• In Formatted Input/Output functions we
should specify the format specifier to make
the compiler to understad the type of values
used to read/write.
The following are the Formatted input/output
functions
• 1. printf()
• 2. scanf()
• 3. fprintf()
• 4. fscanf()
1. printf():
• This function used to display the output on
the console.
• The following the is the syntax to write the
printf() function.
syntax:
printf("Formatstring",list of variables);
Format string is divided into 2 parts they are
i. Text or Message : Some message or text to be
displayed on console. If no text to be
displayed then we cannot write any text.
ii. Format specifiers : Format specifiers of
corresponding datatype will be written.
List of Variables: The variables list to be
displayed on the console. When there is more
than one variable to be displayed, each
variable should be separted by comma (,)
operator.
ex:1
• int a; => %d
• float b; => %f
• char c; => %c
printf("the values are %d%f%c",a,b,c);
printf("the values are %d%f%c",b,c,a); <= Its
incorrect [Mismatch of datatypes]
printf("the values are %d%f%c",a,b); <= Its
incorrect [Mismatch of
Format specifiers and variables number]
Note:
> When we give different types of variables we
must follow the order of format specifiers
with the order of variables list.
> The number of variables must be matched
with the number of format specifiers.
ex:2
• int a,b;
• printf("%d%d",a,b);
2. scanf():
• This function will read the input from the
standard input device(key board) to the
variables.
syntax:
• scanf("Format Specifiers",List of variables);
Ex:1
int a,b;
scanf("%d%d",&a,&b);
• Here the variables must preceed with
address(&) operator.
• All the rules of printf() are applicable here.
Ex:2
• int a;
• float b;
• char c;
• scanf("%d%f%c",&a,&b,&c);
3. fprintf():
• This function will writes the data to the file.
syntax:
fprintf(filepointer,"Format String",List of
variables);
Ex:
• fprintf(stdout,"%d",a);
• Here stdout is standard output device
• You can also specify any other file pointer
4. fscanf():
• This function will read the data from a file.
syntax:
• fscanf(filepointer,"Format Specifiers",List of
variables);
Ex:
• fscanf(stdin,"%d",&a);
• Here stdin is a standard input
device(keyboard)
• You can also specify any other file pointer.
2. Unformatted Input/Output Functions:
• These functions does not required to specify the
format specifier.
• The following are the unformatted input/output
functions.
1. getchar()
2. putchar()
3. getc()/fgetc()
4. putc()/fputc()
5. gets()
6. puts()
1. getchar():
• This function will read a single charecter from
the keyboard.
ex: char ch;
ch=getchar();
2. putchar():
• This function will display a single charecter on
the console.
ex: putchar(ch);
3. getc():
• This function will read a single charecter from
the file.
ex: char ch;
ch=getc(fp);
• here fp is a file pointer from which we need to
read a single charecter.
4. putc():
• This function will write a single charecter to
the file.
ex:putc(ch,fp);
• here fp is file pointer to which we need to
write a single charecter.
5. gets():
• This function will read a string.
• A string is a collection of charecters.
ex:gets(str);
• here str is a string variable.
6. puts()
• This function will display the string on the
console.
ex:puts(str);
• here str is a string variable.
Comment lines:
• Comment lines are ignored by the compiler.
• These are for the information purpose to the
programmer
• The comment lines can be written as a single
line or multiple lines as per theneed.
• We can write the comment line in C Program
between /* and */ symbol.
Ex:
• /* its a declerative statement */
Note:
• 1. All the statements in C language should be
written in lower case
• alphabets only. C language is a case sensitive
language.
• 2. All the statements must be terminated with
semi colon.
write a program to display a welcome message
basics of c programming  for naiver.pptx
To erase the previous output on the console we
can use clrscr() function inthe program.
#include<stdio.h>

More Related Content

Similar to basics of c programming for naiver.pptx (20)

PPTX
Chapter 2: Elementary Programming
Eric Chou
 
PPTX
COMPUTER PROGRAMMING LANGUAGE C++ 1.pptx
atokoosetaiwoboluwat
 
PPTX
Lecture 2 variables
Tony Apreku
 
PPT
programming week 2.ppt
FatimaZafar68
 
PPTX
Introduction to fundamentaals of computing.pptx
shitaldumbre10
 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
EG20910848921ISAACDU
 
PDF
EC2311-Data Structures and C Programming
Padma Priya
 
PPTX
Programming in C by SONU KUMAR.pptx
SONU KUMAR
 
PPTX
C language
Arafat Bin Reza
 
PPTX
Cpu
Mohit Jain
 
PPTX
#Code2 create c++ for beginners
GDGKuwaitGoogleDevel
 
PDF
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
PPT
Basics of c++ Programming Language
Ahmad Idrees
 
PPTX
2. Introduction to 'C' Language (1).pptx
AkshatMuke1
 
PPT
Basics of C.ppt
8759000398
 
PPTX
C Language Part 1
Thapar Institute
 
PPT
Introduction to C
Janani Satheshkumar
 
PPTX
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
PPTX
Fundamental programming Nota Topic 2.pptx
UmmuNazieha
 
Chapter 2: Elementary Programming
Eric Chou
 
COMPUTER PROGRAMMING LANGUAGE C++ 1.pptx
atokoosetaiwoboluwat
 
Lecture 2 variables
Tony Apreku
 
programming week 2.ppt
FatimaZafar68
 
Introduction to fundamentaals of computing.pptx
shitaldumbre10
 
POLITEKNIK MALAYSIA
Aiman Hud
 
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
EG20910848921ISAACDU
 
EC2311-Data Structures and C Programming
Padma Priya
 
Programming in C by SONU KUMAR.pptx
SONU KUMAR
 
C language
Arafat Bin Reza
 
#Code2 create c++ for beginners
GDGKuwaitGoogleDevel
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
Basics of c++ Programming Language
Ahmad Idrees
 
2. Introduction to 'C' Language (1).pptx
AkshatMuke1
 
Basics of C.ppt
8759000398
 
C Language Part 1
Thapar Institute
 
Introduction to C
Janani Satheshkumar
 
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Fundamental programming Nota Topic 2.pptx
UmmuNazieha
 

Recently uploaded (20)

PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Presentation: Climate Citizenship Digital Education
Karl Donert
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
PPTX
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PDF
Comprehensive Guide to Writing Effective Literature Reviews for Academic Publ...
AJAYI SAMUEL
 
PPTX
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
PPTX
SAMPLING: DEFINITION,PROCESS,TYPES,SAMPLE SIZE, SAMPLING ERROR.pptx
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
PPTX
CBSE to Conduct Class 10 Board Exams Twice a Year Starting 2026 .pptx
Schoolsof Dehradun
 
PPTX
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
PPTX
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
 
PPTX
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Presentation: Climate Citizenship Digital Education
Karl Donert
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
digestive system for Pharm d I year HAP
rekhapositivity
 
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Comprehensive Guide to Writing Effective Literature Reviews for Academic Publ...
AJAYI SAMUEL
 
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
SAMPLING: DEFINITION,PROCESS,TYPES,SAMPLE SIZE, SAMPLING ERROR.pptx
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
CBSE to Conduct Class 10 Board Exams Twice a Year Starting 2026 .pptx
Schoolsof Dehradun
 
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
 
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPT on the Development of Education in the Victorian England
Beena E S
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
Ad

basics of c programming for naiver.pptx

  • 1. Day – 01 Problem Solving with Flow Charts & Basics of C Programming
  • 2. The following symbols are used to represent the Flow Charts • Ellipse : To represent start or stop • Parellagram : To represent input/output • Rectangle : To represent the processing or calculations
  • 3. • Rhambus : To represent the conditional statements • Small Circle : To use as a connector • Arrows : For directions
  • 4. 1. Write an algorithm to calculate the addition of 2 numbers. • start • step 1: read a • step 2: read b • step 3: c := a+b • step 4: print a • step 5: print b • step 6: print c • stop
  • 5. 2. Draw the flow chart to calculate the addition of 2 numbers.
  • 6. 3. write an algorithm to calculate the addition of 3 numbers. • start • step 1: read a • step 2: read b • step 3: read c • step 4: d := a+b+c • step 5: print a • step 6: print b • step 7: print c • step 8: print d • stop
  • 7. Rewrite the above the algorithm to represent more input and output(read or print) statements in a single line. • start • step 1: read a,b,c • step 2: d := a+b+c • step 3: print a,b,c,d • stop
  • 8. Draw the flow chart for addition of 3 numbers.
  • 10. • Algorithm 3. write an algorithm to calculate the total marks and average marks of 3 subjects (maths,physics and chemistry) • start • step 1: read maths,physics,chemistry • step 2: total := maths+physics+chemistry • step 3: avg := total/3 • step 4: print maths,physics,chemistry,total,avg • stop
  • 11. Draw the flow chart for the above algorithm
  • 13. Algorithm 4. write an algorithm to calculate the area of a circle. • start • step 1: read radius • step 2: area_circle := 3.14 * radius * radius • step 3: print radius,area_circle • stop
  • 14. Draw the flow chart for the above algorithm
  • 16. Algorithm 7. write an algorithm to find the biggest of two numbers. • start • step 1: read num1,num2 • step 2: if num1 > num2 then • print "num1 is big" • else • print "num2 is big" • stop
  • 17. Draw the flow chart for above algorithm
  • 19. Algorithm 8. write an algorithm to find the biggest of three numbers. • start • step 1: read num1,num2,num3 • step 2: if num1 > num2 and num1 > num3 then • print "num1 is big" • else if num2 > num1 and num2 > num3 then • print "num2 is big" • else • print "num3 is big" • stop
  • 20. Draw the flow chart for the above algorithm
  • 22. Introduction to C Programming Language • C Programming Language is Procedural Programming Language • It is developed by Dennis Ritchie in the year 1972 • It is developed as system programming language to write operating systems and compilers.
  • 23. Features of C Programming Language: • Low level access to memory • rich set of keywords • Alphabets, Digits and Symbols • keywords • statements • programs Alphabets : a-z, A-Z
  • 24. Digits : • 0-9 Symbols : • ~ tilde • ! Exclamatory • @ at the rate • # Hash(preprocessor) • $ Dollar • % Percentage • ^ carret • & ampersand • * star • ( parenthesis open • ) parenthesis close • - highfun/minus • _ underscore • + plus • = equal • : colon
  • 25. • ; semi colon • " Double Quotes • ' Single Quote • < less than • > greater than • , comma • . dot • ? question mark • / slash or division • backward slash • | vertical bar • { brace or curley brace open • } brace or curley brace close • [ bracket open • ] bracket close
  • 26. Keywords : • Keywords are the reserved words in the programming language. • Each keyword in c language is having its own specific purpose and meaning. • These keywords are not used for any other purpose. • All the keywords are written in lower case alphabets.
  • 27. The following are the keywords of C language • auto • break • case • char • const or constant • continue • default • do • double • else • enum • extern
  • 28. • float • for • goto • if • int • long • register • return • short • signed • sizeof • static • struct • switch • typedef • union • unsigned • void • volatile • while
  • 29. Structure of C Programming Language
  • 31. Link/Header File Include Section: • In this section we can include the header libraries or we can link the other • programs with the current programs We can include the header library using the preprocessor directive #includein the program
  • 32. Here # symbol is known as a preprocessor and #include is a preprocessor directive. • Example : • #include<stdio.h> • here stdio.h is a standard input/output header library. • here .h indicates and header library/file.
  • 33. Definition Section: • Here, we define the macro's(constants) or user defined function prototypes. Global Variable Decleration Section: • Here we declare the global variables required in the program.
  • 34. main function: • main function is compulsory in all the c programs. • The program execution always begins from the main function only. (or) • The starting point of C program execution is from main only.
  • 35. • We can write the main function as follows. main() { } : main followed by open parenthesis and closed parenthesis then immediately continued with open brace and closed brace.
  • 36. • We cannot write anything between the closed parenthesis and the open brace of main function. • In between the open brace and closed brace of main function we write the decleration section and execution section.
  • 37. Decleration Section: • In the decleration section we can declare the variables required in the • program. • The first section of main function must be the declreration section.
  • 38. Execution Section: • All the executable statements can be written under the execution section. • The executable statements like input, output and calculation statements.
  • 39. • The main function returns an integer value always, Hence we must write a return statement at the end of main function. • We can write the return statement using the keyword return. example: • return 0;
  • 40. User defined functions: • We can write zero or n number of user defined functions in the C program.
  • 41. Datatypes: • A datatype specifies the compiler that a type of value is stored in the variable.
  • 42. Datatypes: 1. Predefined Datatypes/Basic Datatypes i. integer types - short int - int - long int ii. real types - float - double - long double iii. charecter types - char
  • 43. 2. Derived Datatypes i. arrays ii. strings iii. functions iv. pointers
  • 44. 3. User Defined Datatypes i. structures ii. unions iii. enumerations
  • 47. Identifier: • An identifier is a name of variable, constant, pointer, array, string, function, structure and union.
  • 48. Rules for defining the identifiers: 1. we can use all the lower case alphabets from a to z, digits from 0 to 9 and only one symbol underscore _ in defining the identifier name. 2. we can start with either any alphabet from lower case a to z or _ symbol. 3. we cannot start with any digit. 4. we cannot give any white spaces(space,tab or newline charecter) in the identifier name. 5. The length of an identifier will be from one charecter to 36 charecters.
  • 49. Ex: • a • student_name • gross_salary • _subject • result_1
  • 50. Variable: • A variable is a named memory location to store the values. • We can declare the variables using the datatype as follows. syntax: • datatype variablename;
  • 51. ex: • int num1; • int num2; • int num3; (or) • int num1,num2,num3; • num1=10; • num2=20; • num3=num1+num2;
  • 52. Input/Output functions: • In C language the input/output functions are available in the stdio.h(standard input/output header library). The input/output functions are classified into 2 categories. • 1. Formatted Input/Output Functions • 2. Unformatted Input/Output Functions
  • 53. 1. Formatted Input/Output Functions: • In Formatted Input/Output functions we should specify the format specifier to make the compiler to understad the type of values used to read/write.
  • 54. The following are the Formatted input/output functions • 1. printf() • 2. scanf() • 3. fprintf() • 4. fscanf()
  • 55. 1. printf(): • This function used to display the output on the console. • The following the is the syntax to write the printf() function. syntax: printf("Formatstring",list of variables);
  • 56. Format string is divided into 2 parts they are i. Text or Message : Some message or text to be displayed on console. If no text to be displayed then we cannot write any text. ii. Format specifiers : Format specifiers of corresponding datatype will be written. List of Variables: The variables list to be displayed on the console. When there is more than one variable to be displayed, each variable should be separted by comma (,) operator.
  • 57. ex:1 • int a; => %d • float b; => %f • char c; => %c
  • 58. printf("the values are %d%f%c",a,b,c); printf("the values are %d%f%c",b,c,a); <= Its incorrect [Mismatch of datatypes] printf("the values are %d%f%c",a,b); <= Its incorrect [Mismatch of Format specifiers and variables number]
  • 59. Note: > When we give different types of variables we must follow the order of format specifiers with the order of variables list. > The number of variables must be matched with the number of format specifiers.
  • 60. ex:2 • int a,b; • printf("%d%d",a,b); 2. scanf(): • This function will read the input from the standard input device(key board) to the variables. syntax: • scanf("Format Specifiers",List of variables);
  • 61. Ex:1 int a,b; scanf("%d%d",&a,&b); • Here the variables must preceed with address(&) operator. • All the rules of printf() are applicable here.
  • 62. Ex:2 • int a; • float b; • char c; • scanf("%d%f%c",&a,&b,&c);
  • 63. 3. fprintf(): • This function will writes the data to the file. syntax: fprintf(filepointer,"Format String",List of variables);
  • 64. Ex: • fprintf(stdout,"%d",a); • Here stdout is standard output device • You can also specify any other file pointer
  • 65. 4. fscanf(): • This function will read the data from a file. syntax: • fscanf(filepointer,"Format Specifiers",List of variables);
  • 66. Ex: • fscanf(stdin,"%d",&a); • Here stdin is a standard input device(keyboard) • You can also specify any other file pointer.
  • 67. 2. Unformatted Input/Output Functions: • These functions does not required to specify the format specifier. • The following are the unformatted input/output functions. 1. getchar() 2. putchar() 3. getc()/fgetc() 4. putc()/fputc() 5. gets() 6. puts()
  • 68. 1. getchar(): • This function will read a single charecter from the keyboard. ex: char ch; ch=getchar(); 2. putchar(): • This function will display a single charecter on the console. ex: putchar(ch);
  • 69. 3. getc(): • This function will read a single charecter from the file. ex: char ch; ch=getc(fp); • here fp is a file pointer from which we need to read a single charecter.
  • 70. 4. putc(): • This function will write a single charecter to the file. ex:putc(ch,fp); • here fp is file pointer to which we need to write a single charecter.
  • 71. 5. gets(): • This function will read a string. • A string is a collection of charecters. ex:gets(str); • here str is a string variable. 6. puts() • This function will display the string on the console. ex:puts(str); • here str is a string variable.
  • 72. Comment lines: • Comment lines are ignored by the compiler. • These are for the information purpose to the programmer • The comment lines can be written as a single line or multiple lines as per theneed. • We can write the comment line in C Program between /* and */ symbol.
  • 73. Ex: • /* its a declerative statement */ Note: • 1. All the statements in C language should be written in lower case • alphabets only. C language is a case sensitive language. • 2. All the statements must be terminated with semi colon.
  • 74. write a program to display a welcome message
  • 76. To erase the previous output on the console we can use clrscr() function inthe program.