0% found this document useful (0 votes)
3 views75 pages

C Programming Full Course

C programming, developed by Dennis Ritchie in 1972, is a high-level language standardized by ANSI in 1989. It features a structured approach, dynamic memory allocation, and is case-sensitive, making it suitable for various systems, though platform-dependent. The document covers key concepts such as constants, variables, data types, operators, and the structure of a C program.

Uploaded by

Prajit B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views75 pages

C Programming Full Course

C programming, developed by Dennis Ritchie in 1972, is a high-level language standardized by ANSI in 1989. It features a structured approach, dynamic memory allocation, and is case-sensitive, making it suitable for various systems, though platform-dependent. The document covers key concepts such as constants, variables, data types, operators, and the structure of a C program.

Uploaded by

Prajit B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

C Programming

Dennis Ritchie in 1972 at Belllabs


successor of B language
Standardized ANSI in 1989
by
program compiler objectcode

Level vs
Level language
Low level language High level language
These languages aren't
Machine language
dependent on system
Mateinetta architecture
written in Binary10s andI's
Dependent on system architecture Drawback The computer
Advantage Faster execution has to convert human
readable language to
binary long Machinelong
Assemblyberg Hence slower execution

Languagetranslator
Assembly
Assembler machine
language code

The assembler for high level language is of two types


compiler Interpreter

HLL compiler MIC ALL Interpreter MIC


code code
All lines are converted to A line is converted to
object code first and then object code and is immed
line ately run and so on
runned line by
Translation happens before Translation and execution
execution happens parallely
No file formation of
object code file is formed
object code
and then the contents of
it is executed In order to run the
In order to run the same same program multiple
times the times we need the
program multiple
source code
source code is not executed

object source
Interpreter
296 compiler code code
d
olp Output

Fifitteragehaving
small language 32 keywords
core as other language are
language many
dependent on C language
portable The code can be run in diff systems
Built in functions operators
structured language modular program
pointers
Extensible language
compilation and execution is faster
Dynamic memory allocation
case sensitive language
used to develop and operate embedded systems
Platform dependent
i.e Windows code cannot be run in Linux
and macos and vise versa

structure of a C
Program
Documentation Section comment section
Ex Author
11 Date Effected
A Program for addition of
two numbers
compiler
This section is optional and is
just to
enhance the of program
reading
Link section
include stdio h
Stdiostandard input output
used to include i print
ii scarf
include conio h
Conio consoled input output
used to include getchC
include math h
include str.us
used to perform operations
ng
Definition section

def pi 3.1459
def Max 200

Global declaration section

E void sum This is local void sum


Lhmann
declaration
int c
a when a'has
to be used in
Global
main C times we have to declaration
declare it n times

Main section compulsory

Only one main section per program


fx Void main

declaration
Executable

Subprogram section
Exertion Process
of a C
program
source code

Preprocessor

first.i
edit
Compile

syntax
error

first.am No

assembler
first obs
link with system libraries
first exe
Execute

pita
1
logic
and Data
error
Translational
no
linking and
Output model
loading
Constants in C
constants are fixed values throughout the program

Integer 8yd
numeric Hexadecimal
1 Floating Real constants

Character single character constraints

string constants
Decimal 0 9 Base 10
Integer Octal 0 7 Base 8
Hexadecimal 0 9 A f Base 15

Note
printf Id a
used to print corresponding
print II 97
ASCII values
c 97
Fx printf
Note A 2 65 90 Ofp a
a 2 97 122
0 9 48 57
0 4 6
specialancies 5
note
II
a

Fig
constant
singlecharacter
constant

constant declaration keyword const


Ex void main
define A 10
10 Note No in the
const
If end and look
at the
gaps

Variables in C
It is the name of the memory site that stores
a particular value

Declaration of a variable
Datatype variable name
Ex int a declaration
a 10 initialization
we perform
can declaration and initialization in
well
the same step as
Ex.int a 10
void main

a 10

print i d a

getch

Variable can'tbe
Not chara void
97 is stored in void a
IT a Ascii standard
variable name is assigned as per rules for naming
identifiers and standard keywords cannot be used
as variable name

variable names are case sensitive

Identifiers and keywords in C

These are standard

keywords in C

Datatypes in C
Tells the
type of data that has to be stored in the
memory Also it tells us how much storage memory
to be allocated to a variable

Datatypes

PRIMARY
1
Derived user Defined
int
Array typedef
float structure Enumerated DT
char union
double pointers
void
short int
byte Also signed
It_
int Unsigned
long n bytes
1
For 16 bit computer
Range of signed int 32768 to 32767
Range of unsigned Put 0 to 65535

For 32 bit computer


Range of signed int 2147483648 to 2147483647

Generally size of an integer is 2 bytes

Note I byte 8bits

bytes 8 bits
char
signed 128 to 127
char
Unsigned 0 to 255

Eat bytes
8
3.4238 to 3.4 e
declaration
float format specifier
Ex a
II 0
printf a

IP 10.000000
If
double format specifier
8 bytes
Declaration double a
Format specifier 1 Lf
long double 10bytes
a
I 9
Datatype Range Eyes Format specifier
char or signedchar 128 to 127 1 I C
0 to 255 2 C
unsigned chat
ut or signed int 32768 to 32767 2 d
0 to 65535 2 U
unsigned int

long int 2147483648 to Id


2147483647 4

Y.lu
signed long int 0 to 4294967295 4
128 to 127 I
Short int
o to 255 I
usigned short int

float 3.4238 to 3 4 38 4 f
double 1 Te308 to 1.72308 8 If
Tong double 3.44932 to
1.104932 10 Lf

int 2 bytes
32768 to 32767 Signed int
0 to 65535 unsigned int

Feldotolo
Fedotoooflowest

5535 7 iF It
highes
32768
032768 2 1,0 1,2 327670
65534

unsigned 8 9k o
int 452
327615
2 32766
1

Examplef
include estdio.tn
include conio h
void main

int a 32767
Urser C
printf Id a
getch

OP 32767

include cstdio.hn
include conio h
void main out of rangewon't be shown
But error signedint
circle
32768 the
int a in 32767
32768
Urser afteroccur
Id a will
printf
getch
0p 32768

include cstdio.us
include conio h
void main

int a 32768
UrserC
a
printf L1
9th unsigned int
the no is in the
range of
0 P 32768 unsigned int

Char Ic 1 byte

signed 128 to 127

Unsigned to 255

lowest
Ifotoooo

nIt
255 highest

include stdio.us
void main
To store the value 11
int a 11 have integerand
we
printf id a number system
getche
other parts tents of a code is stored using
character system according to ASCII standards

ASCII encoding scheme contains 256 symbols or

characters

1 151 I
Nd char
char i

F 2

include cstdio.us
void main
addressof
char a a
If suppose the
this block is 102
Char b 98 ASCII value of a is 97
char 2 therefore binary value of 97
Chan D 130 will be stored

unsigned d
char 130

unsigned chard 129


It will print a character
printf Ic a

Id a therefore Olp is a
printf
It will print integer value
i e 97
include csteho.us
void main

char a a
the corresponding binary
value of 98 will
be stored
Char b 98
char 2

Chan d 130
unsigned d
char 130

unsigned chard 129 prints character


Op b
printf Ic b
printf Id b Print integer
0P 98

include csteho.us
void main

7
They

Chan d 130
unsigned d
char 130

unsigned chard 129


printf IC c 2
printf td c
122
include csteho.us
void main

char a a if is mentioned we
nothing
char b 98 take it to be signeddah
char 2
In signed char Max positive
Chan D 130 value in is 127
range
unsigned d
char 130 so in the
signed
chat cird
unsigned chord 129 130 corresponds to 1260
printf Ic d
printf Id d chat
It prints a

Any garbage chart symbol w


OP 126 be printed that corresponds
to 126
Operators in C
Operatorsare symbols that tells the computer to
perform some sort of operations
based on no of operands
Types of operators
minus
unary unary
increment
operato
Binary
logical not
addressof
Ternary
size of
Enffary minus used to change the
sign
int a b
a 5

E
Increases the value by L
2 Increment operator
int y 10
int
y att I
print f fd y
printf fd x n is updated
and stored
Increment operator
IT
is updated
19H Y
y and stored
a remains

not converts true to the same


3 logical file
and vice versa
int y 10
9
int n 11
is true
y r
you
but operator reverses the
ya
output
0p false
Binary Operators
Arithmetic t 1
Relational
logical 88,11
Bitwise 1 CC

Equality operator
comma operator I

Assignment operator
Operator conditional operator
Ternary
expression 1 expression 2 expressions
is true the flow of control moves to
if exp 1
exp 2
if exp 1 is false the flow of control moves

to 3
exp
int a 10 b 15
Ex
asb a b

cond ha
this operator is similar to that of
if else statements

Note Modulo division


Gives REMAINDER
include stdio h
include conio.us
void main

int a 10 b 7
Usac
printf atb d atb 17
b 1d a b 3
printf a

printf a b I d a b 70

printf a b Id a b Quotient
at b Remainder
printf at b 1 d
getchll

Note Modulo operator can be used only with integer


values
values and not with floating point

Basics of precedence and associativity


precedence means higher priority Associativity of
Arithmetic operator
1ˢᵗ precedence
Left Right
2ⁿᵈ precedence
Ex a b
Iff d is calculated
Tendall signs t are of same
precedence Therefroy go from
Assignment operator is
Associativity of assignment operator
Right to left
Fx 9 5 4 Note
variable
always be
LHS should a
a 1 So invalid
a b o is an
statement
first value is assigned to
d then C then b and then a
As per associativity of Assignment operator

Decrement Operator ft
Increment and
springmpetrator

prefix MRI
Postfix
I increment
post operator
int a 10 y
g in second line
printf Id i e
yttx

printf Id y there are 2 operators


increment
assignment and
he precedence of postthe precedence of pre
increment
nurement decrement is that
operator is more than
lesser than assignment
perator Hence of assignment
takes place
assignment happens Therefore first increment
before increment
decrement and then assigned
EX include stdio.is
include conions
Void main

int 9 5 b c d

d tta

printf 1 d a

Memory
storage
IT
I
1 by
18 by so
Final output 8

Relational
Eit
Note is an assignment operator
is equality
an

We can use relational op to compare int float Chak


Fx a b 0P 1 true

9
78 Ascii value

We cannot compare strings using relational operator


EX.I
includeCstdio.h
include Leonio h
void main

int 9 18 b 9
Urser prints integer
printt d a b
printf fd c C'b
getches

0P Both false
8
x.PH include stdio.hn
include conio h
void main

int a 18 6 9 c d e 10

Unscr
c b t 0

ii d acbeesd
printf 1d b ei
printf I d Ise
printf I d atc brecard

a b c

a b c d e

a b c d e

I
Ept 0 false
Note arithmeticoperato
1 True
have more precenden
false
than relational
0 false operator
EX.PH includeCstdio.h
include conio h
void mainC
int a 18 5 9 c d e 10 f
Ihsac

ab IF I Go
f as b dec
Id f time to
print L

print f d at c b e ctd 1
trjtmfalse

oftrujj ti.LI gciaiv


in a

0 1
0

line 10 is 0
Olp of

balstimning operators it
logical AND
logical
I unary operators Not

Expression that contains logical operators in it are


called as logical expression compound relational expression
Relational operators have higher precedence than
Logical operators Both side of Logical operators
can be numbers expression

int a 10 b 5 values

a b
Éme
False t
Logical AND
Final Ofp O false
EI five basis 88 b 10 ball a 5
printf Id result

0p 1 True

kind of Technique is used with 11 and


as
Same
well

Expgy include stdio.hn


main

int a 4b 6 result
result alb print python
printf pd result

result
if If Espen
0P 1 True Also in logical and if
first expression gives zero
E 9 10 5 5
Ttf it won't
expression
go to the other
1 111 4 since ab is zero now it checks
0P O the other side
theflowstops
if first side is 1
includesstdio.us
EXPLI
void main

int a y 5 6 result
result as b print Python print Lecture

printf Id result

SFresult print Python printf lecture


afb
does not check
since as b gives zero 22
the other expression
for
jumps to the expression
towardsthe
Now flow
hand side of II
right
i e printf lecture
and it gives 2
0p
lectured Noffiority of logical
Ex.gg mail not is more than
and
int a y 6 6 result Theorder of priority
print id
lid
4 2810 116
1788
print 4 8255
0P 1
0
Fx main 1
int a 10 b 5 result
result asb 22 att line y
printf Firestult fine
print Id a

3
b result

line 4 the value of a is


After completion of
updated to 11
Therefore the output is
11M

fffhsffstssmta.ee usedto perform operations at a

bit level lowest memory level


in the computer

memory is a bit
We can apply these on int and char values but not
on float
Types of bitwise operators
Bitwise and
1 Bitwise or
BITTLEPot complement
Left shift
right shift

t.IE b
soda
a 1010 a b
D
b 101017
f
0p O

1 Bitwise OR
5
EX.int a 10 6
c a lb

a 1010 B
b 0101 B

a b 1010 ᵗ

in decimal
Bitwise XOR
Ex int a to 5 5
c a b Note A operation

ᵈa 1010
B
gives
input
0
are
if both
same
b 0101 and 1 foropposite
B
1 0 1 0 input
c a b
101
1 1 1 1 0 1
in decimal
I 1
0
0 p 15

Ex.pgm_ maine
int a 10 b 6
Inscres
I d a b 5 1110
Printf

Note priority order


Relational Bitwise logical
Arithmetic
sod
1110
ago 884 0P 1
a 1010
and
b 0110
decimal value_
LL Left shift
var 2
syntax
This means have to shift the vak
you
towards the left by 2 bits

int a 10

0P
an
Eirik
IN ᵈ
E IOIOL i.de
TRICKY
Trailing bits by
are
C a LC b default filled zeros
by
OP
ax2If and Roundoff
decimal point
Right shift

Kif are c a b
we given
then C
and Roundoff
decimalpoints
it
O P
c
4 2 2
Bitwise Not

int 9 5
b na

Sof 101 B

b 0101 1010 B
B
10
in decimal
Therefore op

Special Operators
mm

size of fathers immense


comia selection operators
comma has the least precedence and
Associativity is L R
Ex int a b c Here comma acts as a

separator
int a
Here comma act as an operator
a 5,4
Here we have comma and assignment operator
Assignment happens first higher priority

This means a is already


Now
assigned by 5
4 is of no use
This statement gives error because int a
5,4
means int 925 int 4 which is an invalid
statement
int a
9 5 4

when comma is used it means the first value is


assigned and the rejected Then the second value
n assigned and also
returned

E int a there first value is


assigned and
n
printf Jenny 2 executed

0P
and then rejected
Jenny Then second value is
2
assigned
into
a print Jenny 2,3

0p Jenny

int 9 8 b
II
b att a

Be
I
Ex int 0 8 b
b att a
a
15
Ga 138
a
Is
Operator Precedence and Associativity
prefix
postfix R I
sizeof type R L 2

L R 3
R 4
LL R 5
R 6
L R 7
R 8
L R 9
I L R 10
R 11
11 LTR 12
R L 13
1 C R L 16
9 R 15
Formatted Input function in C

TTTeeps the user


get input from
General syntax
2
scanf controlstring sang2 Carg

control string
d or If or C
t
for inputting forfloat for char

infan
E include stdio.is
include Clonio h
main
as
written twice
int b sum
a we are getting 2 inputs
Insors from the user
scant Ted a b

sum atb
note were is address
of operator
will
of 1 d
instead we it
if use a means

instance stole the value in


Ad for the address of a
1 and helps us to get in
4 digit input from the user
EI inta floatb char c

scarf t.de fyc a b C

d d b
EI n_scant a

sum atb
print sum I d sum

Formatted Output functions


printfc

SMI print control string aug 1 age align

E main

int a b sum
print Enter two numbers
b
scant Id Id a

sum atb
printt Id sum line

I Format integervalue
printing
specifier for

line 7 can be also written as

print sum Id sum


NE ex A 1234
print f fed a
stored as

4
a 1234
printt food a
stored as
61010
a 1234
print f a

tiff
This means it can store 10 decimal
digits and 2 digits after the decimal
point
Functions
Unformatted
we
Input we

getchart mains
getche
March
getchel ch _getchart
gets1
print t.ci ch

input
Euthereen skimmo
J Output
It prints only first
was
In getchl the moment we press a chat the control
the next line without displaying
goes to instantly
the character
at the end of all programs
we use getchi
to use it the output
to hold the output If we fail
just flashes the screen and disappears instantly

In getchel the moment we press the character


it is displayed and also the next line is runned

is used to take complete as an


gets a string
input
Ex main

char ch 10
gets ch
s ch
printf ch

OIPscreen c programming input


ch c programming output

Unformatted Output functions in C


we
putchall
putchl
putsC
includecstdio.hn
include conio.us
void main

char ch
Enter char
print a

ch getche
printf In character is t.ci ch

getches

enter cue a g
open
character is 5

We can also use use putchall here


But the drawback is we can't use
only
any sort of formatspecifier
character
Nyte
Putchar is used only for single
output
The difference bw put charll and putch
only while
is that putchall is defined in cstdio.hn
putch is defined in sconio h
puts is used to print whole strings
Control Statements

if
if else
if else if ladder
Nested if
switch
if statement
if condition
statement
after if statements
void main

int a
Enter a
printff
scarf f d a

if a

print Inside if block

printf out of if block


getchl

Ofp Enter a 5
Inside if block
if block
low chart
1
false
Condition

True
statement block

After if statements 4
Note
if we are using multiple statements after
statements
if statement we enclose these
with
E void main

int a
Enter a
printff
scarf f d a

if a

printf Inside if block


printf Alright

printf out of if block


getchl
Ex.IM void main

int
age
the age
print Enter
scant Id age
if age 20

printf Yourage is Id age


print f You can go to office with me

time to
print Its go home

getch
0P Enter 15
age
Its time to home
go
Enter age 21

Your age is 21
You can go to office with
me

Its time to
go home
If else
if condition

true block statements

else
false block statements
after if else block statements
1
false
Condition

True

True Block statements false Block statement

After if elseblook statements


Ext mains

int age
print f Futer age
scarf fd age
if age 258 age 30

printf age I d age


print coffee with me
else

printf age fd age


print Go home

printf out ofelse


3
Enter age 25
UP
age 25
coffee with me
Out of if else
Enter age 20
20
age
Go home
out of if else
Nested if
if condition 1

condition 2
if
Inner if blockstatements
else
inner else block statements

else

outer else block statements

outer nested if statements


xgm
Void main
int age
salary
Enter and salary
printf age
Scant t.de d age salary
if age 50

if salary 260000

salarysalary 1000

else
salary Salary 5000

else

3000
salary Salary

printf End of the


program
getchC
else if ladder
used to take multipath decisions
Syntee conditions
if
statement
else if Icondition 2

statement 2
else if condition
statement 3

else if condition n

statement n

else
Default statement
statement
Ex Pgm
void main

int marks
print Enter marks
scarf Id marks
if marks 780
printf Grade is A
else if marks 370
print B Grade
else if marks 60

print C grade
else if marks 55
print D grade
else
print f fail

print End of program


getch

Futer marks 80
C grade
End of program
Switch in C

Multi decision
statement
way
syntax switch expression

case value t
Block of statements
break
Case value 2
Block of statements
break
default
default statements

Statement N

E print Entera
Scant Id a

switch a

cases
printfl TK
break
case
printf Name
break
default
print Bye

print Go to home

a 2 Enter a b
Engine
Go to home
Go to home

EI printf Enter a
a
scant fd
switch 12
24 By default takes the argument
as mandancogresponds
case 5 print JK
break
case 4 print Hehe
break
default
print Bye
OII Hehe
Bye
Flowchart 1
Expression

Tisegualtered
Casevaluef
yeah
f
no

wdfak
Ésffdt
No i

1
Treating
Handoff statement
C program for a
simple calculator
include station
include conio.us
void mains

int a b Swm Sub dir mel


Char operator
printf Enter the operator

scarf 1 c operator
Enter two operands
print
1 did Ia Ib
scarf
Switch operator

case t sum atb


printf sum t d sum
break
case sub a b

print sub I d sub

case mhd a b
mul I d mel
print
case 851 a b
div f d dir
printf
break
default print Enter valid operator

getchel
Loops in C

controlled loop condition is right at the


Entry start The control goes
Exit controlled
loop into the loop bodyonly
1 if the condition holds
condition is at the end
Once the control flows over
condition
the body
of the loop then if
satisfies it runs again iterate

For loops

TEntry controlled loop

8Mt initialization condition update modify


for Expression 1 Expression 2 Expression 3

11 loop body

Es for i 1 9 10 itt

print E t.dk i

01
I
first i initialized there is a space in the
is
memory for i and its now filled with 1 Now
Now it holds hence it goes to
it checks if i 2 10

the body the loop and prints it After that


of
the control to the update modify section
goes
i.e it now the memory is updated
of the for loop
to 1 2 now it checks if 1 2 is ic 10 since

its true it print the body of the loop and then


updates 1 3 in memory and so on

Flowchart
Initializations

false A
Lafon
Bodyofloopf
I
true

modifylupdated

outof the loop


properties of toh loop Initialization
for expression 1 expression 2 expression 3

11Body of loop

FI void main
int i
for i i2 5 it t

printf t.dk i

geth
3
You can initialize the variable
It void main
outside the for loop and
int i 1 leave the initialization
for ic 5 it t part of the for
i
he ends
T.tt dim i

geth
3
void main initialize anywhere
when we don't
it will not give
int any
for i ic 5 itt output

printf t.dk i

geth
3
when we have to initialise two variables at
the same time we enclose them separated
comma
by a

include Lstdio.us
include conions

int i
for i 0 ices itt

print Id Id In i j

getche

we canput no condition no expression 2 in for


loop to create an infinite loop and also we can give
more than one condition as well by separating them

by a comma we can also use operations like 11


between two condition to perform appropriate logical
operations
include stdio.us
forms an infinite
include conions loop
0P 1 0
inti 2 0
for 1 1 1 0 itt 3 0
e
4 0

print Id Id In i j

getche

include stdio.us
I
include conions

inti
for 1 1 1 0 1 5,143 itt

print Id Id In i j

getche

Note when we
give multiple conditions then the
last is treated as the termination statement
statement
i e the loop terminates only after the last statement
is completely executed
OP 1 0 Forms an infinite loop as
2 0 the termination condition is
1 0 which is always true
3,0 the condition termination is
of
not getting updated here

C
program
to print table of a number

include cstdio.hn
include cconio.us
void main

Enter the value a


fief of
scarf Id a

for i 1 10 itt

r a
print ati I.dk 0

getchell

Ip Enter the value


2
of a 2

4
6
8
20
while loop

syntax initialization
while condition

statement 1

statement n

update modify

Ehrhart Initializations
false fonditiont
find
statementfBo

modify
C
program
to print table of a number
using whileloop
include cstdio.us
include conions
void main

int i t
while 10

printf Id in i
Itt

getchi

EI void mainll

int i 1 considered
boolean 1
while i 10 as
True
fd i
print
tti
End of Program
print note when we use
getchC
while 1 it means
it always true condits
IP a loop
Do while Loop
for and while loop are entry control loop but dowhile
loop is exit control loop

Syntax Initialization
do
statements

modify update

while condition

statement

Incrementlemment
t
True Condition
false
t
without ducking anything control enters the loop then
condition is checked if it satisfies again it runs back
the loop but if its not satisfied it goes out the
loop
But atleast one time the loop body is executed
Difference between for while do while loop in C

For While Do while


entry controlled Entry controlled Exit controlled
initialization do
for initialization while condition
conditionupdate statement 1
11
Bodyofloop
11
Body ofloop update start
while condition
Used when noof used when no
of used when no
of
iterations are known iterations is not iterations is not
control will not enter known known
into the loop if control will not enter Body of the
condition is false into the loop if
loop
condition is false will be executed
atleast once

break statement in C

Note break statement should always be written in


small letter as break is a keyword
break statements can be executed either in a
loop oh
switch statements
that gets not
orgsituation A program more than 5 inputs from
the user and print the sum of those 5ns
If the user enters a
negative number
the program stops getting
further inputs and
prints the sum
of
numbers that was above
the negative number
include stdio.us
include conion
void main
int a i sum 0

for i is 5 itt

printf Enter a number


scarf Id a

if azo

break

sum sum a

printf Id sum
a i sum

0P Enter a number I
Enter a number 4 D
Enter a number 7 12
Enter a number I IF
break

As If the condition is
changed as
The he she
user can enter as many number
wishes but when he inputs a negative number the
loop breaks The program looks like
include stdio h
include conio h's
void main11
int a sum O
while s

printf Enter a number

scarf Id a

if aco

break

Sum Sum a

printf sum Id sum

Continue statement in
C when we use continue
statement
the control does not flow to the next statements
down but it
goes back increment decrement update
section of the loop

If we use break statement the flow of control


the loop if
goes out of But we
continue start
use

the flow goes to update section and makes the loop run
again
for initialization condition update

statement
statement z f condition satisfied
conditin
if condition
if
not continue Does not get
statement 3
satisfy Statement 4
executed

statement R
3

false loop
condition

true update
condition true
continue

false
v

Stalementf Remaining statement


the loop
of
that
Prgsituation A program gets not more than 5 inputs
from
the user and print the sum of those 5ns
If the user enters a negative number
that input is not considered and it gets
remaining inputs

includesstdio.hr
include conio h
void main
int i a sum 0
for i L 1 5 itt

printf lieutes a number


Scarf
Nested for loops

program case You are supposed to print the following


pattern in

for 1 1 1 6 Itt
FI IIEE

for i 1 1 5 it

printfe
p nt In
False outer
loopondition

True
False Inner
loopondition

Outerloop
SB true

Update Exp Insaf


uterloop
Updategpf

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy