SlideShare a Scribd company logo
Introduction To C
Programming
What is C ?
C is a programming language developed at
AT & T’s Bell Laboratories of USA in 1972.
 C language was designed and written by
DENNIS RITCHIE.
Why to use C ?
• C is a language which is Simple,Fast and Small.
• C is very important language of programming
and is a good base for learning C++,C# or JAVA
later.
• Unix, Linux, Windows are written C.
• Gaming is also written in C.
• Embedded and Mobile devices use C.
• C offers better interaction with Hardware.
ENGLISH v/s C
Engilsh C
Alphabets, Digits Alphabets ,Digits ,Special Symbols
Words, Numbers Constants , Variables, Keywords
Sentences Statements or Instructions
Paragraphs Programs
Alphabets, Digits, Special Symbols
Alphabets – A to Z, a to z
Digits – 0 to 9
Special Symbols - !,*,%,/….to32
Constants & Variables
5x+10y
Variables
Constants
Constants(Literals)Cannot Change
Integers
Real or Floats
Characters
Pointers
Array
String
Structure
Unions
Enum
Primary
Secondary
Rules for Integer Constants
I
• Must have atleast one digits.
II
• No Decimal points.
III
• Either +ve or –ve.
IV
• If no sign precedes an integer constant, it is assumed to be +ve.
V
• No commas or blanks are allowed.
VI
• Valid range -2147483648 to 2147483648
Example: 421 -66 -7856 999 -69
1,200 1 2 3
42 -69
64.99
4
Rules for Real/Float Constants
I • Must have atleast one digits.
II • Must contain a decimal point.
III • May be +ve or –ve.
IV • Default is +ve.
V • No commas or blanks are allowed.
VI • Valid range -3.4x1038 to 3.4x1038
Examples: +325.34 426.0 -32.76 -48.5792
Real Constants
• In exponential form the real constant is
represented in two parts.
• Part appearing :
Before ‘e’ is called Mantissa
After ‘e’ is called Exponent
3.24x10-4 Can be written in C
as
3.24e-4
Rules for Real Constants Expressed in
Exponential Form
I
• The mantissa part and exponential part should be separated by a
letter e or E.
II
• Mantissa part may have a +ve or-ve sign(Default is +ve).
III
• Exponent must have alteast one digit, which must be +ve or -ve
(Default is +ve).
IV
• Valid Range is -3.4e38 to 3.4e38
Examples: +3.2e-5 4.1e8 -0.2E+3 -3.2e-5
Rules for Character Constants
I
• It is a single alphabet, digit or special symbol
II
• Must be enclosed within a pair of ’ ’
• Both the inverted commas should point to the left.
For example, ’A’ is valid whereas ‘A’ is not valid.
Examples: ’A’ ’3’ ’m’ ’+’
C Variables
It is an entity whose value can change.
It is a name given to a location in memory.
Example:
x=3
y=4
z=x+y
Therefore, z=7
Types of C Variables
Integer
Real
Character
Pointer
Array
String
Structure
Union
Enum
Primary
Secondary
Constants & Variable Types
int a float b char c
a=3 b=3.0 c=’3’
Would
this
Work?
3 3.0 ’3’ a b
Integer
Constant
Real
Constant
Char
Constant
? ?
c
?
•int xyz
•int abc123
• int 123abc
Rules For Building Variable Name
I
• First character must be alphabet
II
• Rest can be alphabets, digits or underscores(_)
• Example:- hi69 si_int
III
• Length <=8(Usually)
IV
• No commas or spaces
V
• Variable names are case sensitive
• Example:- ABC abc Abc aBc AbC
si-int
si_int
All are different
C Keywords
• Keywords are the words whose meaning has already
been explained to the C compiler(or in a board sense
to the computer).
• There are only 32 keywords available in C.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Rules for FORM of C Program
a) Each instruction in C program is written as a
separate statement.
b) The statement in a program must appear in the
same order in which we wish them to be
executed.
c) Blank spaces may be inserted between two
words to improve readability of the statement.
d) All statement should be in lower case letters.
e) Every C statement must end with a semicolon(;).
Thus ; acts as a statement terminator.
The First C Program
#include<stdio.h>
int main()
{
float p,r,si;
int n;
p=1000;
r=8.5;
n=3;
si=p*n*r/100;
printf(“S.I.=%f”,si);
return 0;
}
All variable must be declared
+ - * / are Arithmetic Operators
; is a statement terminator
Printing Values
float p,r,si;
int n;
p=1000;
r=8.5;
n=3;
si=p*n*r/100;
printf(“S.I.=%f”,si);
Format
String
Format
Specifier
( ) Parantheses
{ } Braces
[ ] Brackets
1000 3 8.5
255.00
p n r
si
General Form of printf()
printf(“format string”,list of variables);
Ex. printf(“%f%i%f%f”,p,n,r,si);
• %i - integer
• %f - float
• %c - char
Format
String can
contain
Sequence is Important
What to Execute
#include<stdio.h>
int main()
{
float p,r,si;
int n;
p=1000;
r=8.5;
n=3;
si=p*n*r/100;
printf(“S.I.=%f”,si);
return 0;
}
Return
type
Function
For printf()
to work
Scope
Delimiters
Success return(0); Optional
 Comments are used in a C program to clarify the purpose of
the program or statement in program.
 Tips About Comments:-
Any number of comments anywhere
/*formula*/ si=p*n*r/100; /*formula*/
Multi-line comments are OK
/* Hi welcome to C programming
Calculate Simple Interest*/
Nested comments are NOT OK
/*…………………./* …………..*/…………………*/
Comments
Comments Are Useful
/*Calculation of simple interest*/
#include<stdio.h>
int main()
{
float p,r,si;
int n;
p=1000;
r=8.5;
n=3;
si=p*n*r/100;
printf(“S.I.=%f”,si);
return 0;
}
Comment
What is main()?
• main() is a function
• A function is container for a set of statements.
• All statements that belong to main() are enclosed within a
pair of braces{ } .
• main() always returns a an integer value,hence
there is an int before main(). The integer
value that we are returning is 0. 0 indicates
success.
• Some compliers like Turbo C/C++ even
permits us to return nothing from main( ).
In this case we use the keyword void. But it is
non-standard way of writing
int main( )
{
statement 1;
statement 2;
statement 3;
}
scanf( )
 To make the program general, i.e. the program itself should ask the
user to supply the values through the keyboard during execution.
This can be achieved using a function called scanf( ) .
 printf( ) outputs the value to the screen whereas scanf( ) receives
them from the keyboard.
 General Form:-
scanf(“%d”,&ch);
• The format specifier %d is used in scanf() statement.
• Address of operatoris used before variable name “ch” in scanf()
statement as &ch.
Format
Specifier
Ampersand or
Address of Operator
Program through scanf( )
#include<stdio.h>
int main()
{
float p,r,si;
int n;
printf(“Enter the values of p,n,rn”);
scanf(“%f%d%f”,&p,&n,&r);
si=p*n*r/100;
printf(“S.I.=%f”,si);
return 0;
}
OUTPUT:-
Enter the values of p,n,r
1000
5
15.5
S.I.=775
It is for Newline
i.e n
One More Program
/*Calculation of average*/
#include<stdio.h>
int main()
{
int n1,n2,n3,avg;
printf(“Enter values of n1,n2,n3n”);
scanf(“%d%d%d”,&n1,&n2,&n3);
avg=(n1+n2+n3)/3;
printf(“Average=%d”,avg);
return 0;
}
OUTPUT:-
Enter values of n1, n2, n3
3
5
4
Average=4
SUMMARY
• 3 top reasons for learning C:
- Good base for learning C++,C# or JAVA later
- Unix, Linux, Windows, Gaming frameworks are written in C
-C offers better interaction with H/W.
• Constants=Literals->Cannot Change
Variables=Identifiers->May Change
• Types of variables and constants:
1)Primary 2)Secondary
• 3 types of primary:
1)integer 2)Real(float) 3)character
• Ranges:
1) 2-byte integers: -32768 to 32768
2) 4-byte integers: -2147483648 to 2147483648
3) floats: -3.4x1038 to 3.4x1038
• In a char constant both quotes must slant to left like ’A’
• Variables has 2 meanings:
1) It is an entity whose value can change
2)It is a name given to a location in memory
• Variable names are case-sensitive and must begin with an alphabet
• Total keyword=32.Example int, char, float
• printf( ) is a function that can print multiple constants, variables and
expressions
• Format specifiers in printf( ),scanf( ):
int - %i
float - %f
char - %c
• main( ) is a function that must always return an integer value:
0 – if it meets success
non zero – if it encounters failuire
• Use/*………………*/for a comment in a program
• & is “address of operator ” and must be used before a variable in scanf( )
• Reference Book:-

More Related Content

What's hot (20)

PPT
C the basic concepts
Abhinav Vatsa
 
PPTX
Managing input and output operations in c
niyamathShariff
 
PPT
Operation on string presentation
Aliul Kadir Akib
 
PPTX
C tokens
Manu1325
 
PPSX
C programming basics
argusacademy
 
PDF
Factorial Program in C
Hitesh Kumar
 
PPTX
datatypes and variables in c language
Rai University
 
PPT
c-programming
Zulhazmi Harith
 
PPTX
What is Switch Case?
AnuragSrivastava272
 
PPT
Types of operators in C
Prabhu Govind
 
PPTX
introduction to c language
Rai University
 
PPTX
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
PDF
Features of c
Hitesh Kumar
 
PPTX
C if else
Ritwik Das
 
PPTX
Unit 4. Operators and Expression
Ashim Lamichhane
 
PPT
Introduction to c programming
ABHISHEK fulwadhwa
 
DOCX
C Programming
Sumant Diwakar
 
PPTX
Introduction to c programming
Manoj Tyagi
 
PPT
Variables in C Programming
programming9
 
PPTX
Register Transfer Language,Bus and Memory Transfer
lavanya marichamy
 
C the basic concepts
Abhinav Vatsa
 
Managing input and output operations in c
niyamathShariff
 
Operation on string presentation
Aliul Kadir Akib
 
C tokens
Manu1325
 
C programming basics
argusacademy
 
Factorial Program in C
Hitesh Kumar
 
datatypes and variables in c language
Rai University
 
c-programming
Zulhazmi Harith
 
What is Switch Case?
AnuragSrivastava272
 
Types of operators in C
Prabhu Govind
 
introduction to c language
Rai University
 
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
Features of c
Hitesh Kumar
 
C if else
Ritwik Das
 
Unit 4. Operators and Expression
Ashim Lamichhane
 
Introduction to c programming
ABHISHEK fulwadhwa
 
C Programming
Sumant Diwakar
 
Introduction to c programming
Manoj Tyagi
 
Variables in C Programming
programming9
 
Register Transfer Language,Bus and Memory Transfer
lavanya marichamy
 

Viewers also liked (12)

PPTX
Introduction to C programming
Rokonuzzaman Rony
 
PPTX
Mickey mouse
templatesforpowerpoint.com
 
PDF
structured programming Introduction to c fundamentals
OMWOMA JACKSON
 
PPT
Why C is Called Structured Programming Language
Sinbad Konick
 
PPTX
Green chemistry
Aniket Patne
 
PPTX
Programmer ppt
SirVishalot
 
PPT
Biotechnology
NivethaRavi
 
PPTX
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
PPTX
Biotech & medicine.ppt
Mahin Nwx
 
PPSX
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
PPTX
Solar panel Technology ppt
Gourav Kumar
 
PPT
Solar energy ppt
shubhajit_b
 
Introduction to C programming
Rokonuzzaman Rony
 
structured programming Introduction to c fundamentals
OMWOMA JACKSON
 
Why C is Called Structured Programming Language
Sinbad Konick
 
Green chemistry
Aniket Patne
 
Programmer ppt
SirVishalot
 
Biotechnology
NivethaRavi
 
Biotech & medicine.ppt
Mahin Nwx
 
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Solar panel Technology ppt
Gourav Kumar
 
Solar energy ppt
shubhajit_b
 
Ad

Similar to Introduction to C Programming (20)

PDF
C SLIDES PREPARED BY M V B REDDY
Malikireddy Bramhananda Reddy
 
PPTX
C introduction
AswathyBAnil
 
PPTX
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
EG20910848921ISAACDU
 
PPT
270_1_ChapterIntro_Up_To_Functions (1).ppt
GayathriShiva4
 
PPT
270_1_CIntro_Up_To_Functions.ppt
JoshCasas1
 
PPT
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
muhammedcti23240202
 
PPT
Introduction to C Programming
MOHAMAD NOH AHMAD
 
PPT
Unit 4 Foc
JAYA
 
PPT
CONSTANTS, VARIABLES & DATATYPES IN C
Sahithi Naraparaju
 
PPT
constants, variables and datatypes in C
Sahithi Naraparaju
 
PPT
Survey of programming language getting started in C
ummeafruz
 
PPT
270_1_CIntro_Up_To_Functions.ppt
Alefya1
 
PPT
270_1_CIntro_Up_To_Functions.ppt
UdhayaKumar175069
 
PPT
270 1 c_intro_up_to_functions
ray143eddie
 
PPT
Unit i intro-operators
HINAPARVEENAlXC
 
PPTX
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
PDF
UNIT1 PPS of C language for first year first semester
Aariz2
 
PPTX
unit 1 cpds.pptx
madhurij54
 
PPTX
Cpu
Mohit Jain
 
PPT
All C ppt.ppt
JeelBhanderi4
 
C SLIDES PREPARED BY M V B REDDY
Malikireddy Bramhananda Reddy
 
C introduction
AswathyBAnil
 
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
EG20910848921ISAACDU
 
270_1_ChapterIntro_Up_To_Functions (1).ppt
GayathriShiva4
 
270_1_CIntro_Up_To_Functions.ppt
JoshCasas1
 
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
muhammedcti23240202
 
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Unit 4 Foc
JAYA
 
CONSTANTS, VARIABLES & DATATYPES IN C
Sahithi Naraparaju
 
constants, variables and datatypes in C
Sahithi Naraparaju
 
Survey of programming language getting started in C
ummeafruz
 
270_1_CIntro_Up_To_Functions.ppt
Alefya1
 
270_1_CIntro_Up_To_Functions.ppt
UdhayaKumar175069
 
270 1 c_intro_up_to_functions
ray143eddie
 
Unit i intro-operators
HINAPARVEENAlXC
 
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
UNIT1 PPS of C language for first year first semester
Aariz2
 
unit 1 cpds.pptx
madhurij54
 
All C ppt.ppt
JeelBhanderi4
 
Ad

Recently uploaded (20)

PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Dimensions of Societal Planning in Commonism
StefanMz
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
community health nursing question paper 2.pdf
Prince kumar
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 

Introduction to C Programming

  • 2. What is C ? C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972.  C language was designed and written by DENNIS RITCHIE.
  • 3. Why to use C ? • C is a language which is Simple,Fast and Small. • C is very important language of programming and is a good base for learning C++,C# or JAVA later. • Unix, Linux, Windows are written C. • Gaming is also written in C. • Embedded and Mobile devices use C. • C offers better interaction with Hardware.
  • 4. ENGLISH v/s C Engilsh C Alphabets, Digits Alphabets ,Digits ,Special Symbols Words, Numbers Constants , Variables, Keywords Sentences Statements or Instructions Paragraphs Programs
  • 5. Alphabets, Digits, Special Symbols Alphabets – A to Z, a to z Digits – 0 to 9 Special Symbols - !,*,%,/….to32
  • 7. Constants(Literals)Cannot Change Integers Real or Floats Characters Pointers Array String Structure Unions Enum Primary Secondary
  • 8. Rules for Integer Constants I • Must have atleast one digits. II • No Decimal points. III • Either +ve or –ve. IV • If no sign precedes an integer constant, it is assumed to be +ve. V • No commas or blanks are allowed. VI • Valid range -2147483648 to 2147483648 Example: 421 -66 -7856 999 -69 1,200 1 2 3 42 -69 64.99 4
  • 9. Rules for Real/Float Constants I • Must have atleast one digits. II • Must contain a decimal point. III • May be +ve or –ve. IV • Default is +ve. V • No commas or blanks are allowed. VI • Valid range -3.4x1038 to 3.4x1038 Examples: +325.34 426.0 -32.76 -48.5792
  • 10. Real Constants • In exponential form the real constant is represented in two parts. • Part appearing : Before ‘e’ is called Mantissa After ‘e’ is called Exponent 3.24x10-4 Can be written in C as 3.24e-4
  • 11. Rules for Real Constants Expressed in Exponential Form I • The mantissa part and exponential part should be separated by a letter e or E. II • Mantissa part may have a +ve or-ve sign(Default is +ve). III • Exponent must have alteast one digit, which must be +ve or -ve (Default is +ve). IV • Valid Range is -3.4e38 to 3.4e38 Examples: +3.2e-5 4.1e8 -0.2E+3 -3.2e-5
  • 12. Rules for Character Constants I • It is a single alphabet, digit or special symbol II • Must be enclosed within a pair of ’ ’ • Both the inverted commas should point to the left. For example, ’A’ is valid whereas ‘A’ is not valid. Examples: ’A’ ’3’ ’m’ ’+’
  • 13. C Variables It is an entity whose value can change. It is a name given to a location in memory. Example: x=3 y=4 z=x+y Therefore, z=7
  • 14. Types of C Variables Integer Real Character Pointer Array String Structure Union Enum Primary Secondary
  • 15. Constants & Variable Types int a float b char c a=3 b=3.0 c=’3’ Would this Work? 3 3.0 ’3’ a b Integer Constant Real Constant Char Constant ? ? c ? •int xyz •int abc123 • int 123abc
  • 16. Rules For Building Variable Name I • First character must be alphabet II • Rest can be alphabets, digits or underscores(_) • Example:- hi69 si_int III • Length <=8(Usually) IV • No commas or spaces V • Variable names are case sensitive • Example:- ABC abc Abc aBc AbC si-int si_int All are different
  • 17. C Keywords • Keywords are the words whose meaning has already been explained to the C compiler(or in a board sense to the computer). • There are only 32 keywords available in C. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
  • 18. Rules for FORM of C Program a) Each instruction in C program is written as a separate statement. b) The statement in a program must appear in the same order in which we wish them to be executed. c) Blank spaces may be inserted between two words to improve readability of the statement. d) All statement should be in lower case letters. e) Every C statement must end with a semicolon(;). Thus ; acts as a statement terminator.
  • 19. The First C Program #include<stdio.h> int main() { float p,r,si; int n; p=1000; r=8.5; n=3; si=p*n*r/100; printf(“S.I.=%f”,si); return 0; } All variable must be declared + - * / are Arithmetic Operators ; is a statement terminator
  • 20. Printing Values float p,r,si; int n; p=1000; r=8.5; n=3; si=p*n*r/100; printf(“S.I.=%f”,si); Format String Format Specifier ( ) Parantheses { } Braces [ ] Brackets 1000 3 8.5 255.00 p n r si
  • 21. General Form of printf() printf(“format string”,list of variables); Ex. printf(“%f%i%f%f”,p,n,r,si); • %i - integer • %f - float • %c - char Format String can contain Sequence is Important
  • 22. What to Execute #include<stdio.h> int main() { float p,r,si; int n; p=1000; r=8.5; n=3; si=p*n*r/100; printf(“S.I.=%f”,si); return 0; } Return type Function For printf() to work Scope Delimiters Success return(0); Optional
  • 23.  Comments are used in a C program to clarify the purpose of the program or statement in program.  Tips About Comments:- Any number of comments anywhere /*formula*/ si=p*n*r/100; /*formula*/ Multi-line comments are OK /* Hi welcome to C programming Calculate Simple Interest*/ Nested comments are NOT OK /*…………………./* …………..*/…………………*/ Comments
  • 24. Comments Are Useful /*Calculation of simple interest*/ #include<stdio.h> int main() { float p,r,si; int n; p=1000; r=8.5; n=3; si=p*n*r/100; printf(“S.I.=%f”,si); return 0; } Comment
  • 25. What is main()? • main() is a function • A function is container for a set of statements. • All statements that belong to main() are enclosed within a pair of braces{ } . • main() always returns a an integer value,hence there is an int before main(). The integer value that we are returning is 0. 0 indicates success. • Some compliers like Turbo C/C++ even permits us to return nothing from main( ). In this case we use the keyword void. But it is non-standard way of writing int main( ) { statement 1; statement 2; statement 3; }
  • 26. scanf( )  To make the program general, i.e. the program itself should ask the user to supply the values through the keyboard during execution. This can be achieved using a function called scanf( ) .  printf( ) outputs the value to the screen whereas scanf( ) receives them from the keyboard.  General Form:- scanf(“%d”,&ch); • The format specifier %d is used in scanf() statement. • Address of operatoris used before variable name “ch” in scanf() statement as &ch. Format Specifier Ampersand or Address of Operator
  • 27. Program through scanf( ) #include<stdio.h> int main() { float p,r,si; int n; printf(“Enter the values of p,n,rn”); scanf(“%f%d%f”,&p,&n,&r); si=p*n*r/100; printf(“S.I.=%f”,si); return 0; } OUTPUT:- Enter the values of p,n,r 1000 5 15.5 S.I.=775 It is for Newline i.e n
  • 28. One More Program /*Calculation of average*/ #include<stdio.h> int main() { int n1,n2,n3,avg; printf(“Enter values of n1,n2,n3n”); scanf(“%d%d%d”,&n1,&n2,&n3); avg=(n1+n2+n3)/3; printf(“Average=%d”,avg); return 0; } OUTPUT:- Enter values of n1, n2, n3 3 5 4 Average=4
  • 29. SUMMARY • 3 top reasons for learning C: - Good base for learning C++,C# or JAVA later - Unix, Linux, Windows, Gaming frameworks are written in C -C offers better interaction with H/W. • Constants=Literals->Cannot Change Variables=Identifiers->May Change • Types of variables and constants: 1)Primary 2)Secondary • 3 types of primary: 1)integer 2)Real(float) 3)character • Ranges: 1) 2-byte integers: -32768 to 32768 2) 4-byte integers: -2147483648 to 2147483648 3) floats: -3.4x1038 to 3.4x1038 • In a char constant both quotes must slant to left like ’A’ • Variables has 2 meanings: 1) It is an entity whose value can change 2)It is a name given to a location in memory • Variable names are case-sensitive and must begin with an alphabet
  • 30. • Total keyword=32.Example int, char, float • printf( ) is a function that can print multiple constants, variables and expressions • Format specifiers in printf( ),scanf( ): int - %i float - %f char - %c • main( ) is a function that must always return an integer value: 0 – if it meets success non zero – if it encounters failuire • Use/*………………*/for a comment in a program • & is “address of operator ” and must be used before a variable in scanf( )