Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

C Language

Input and output instruction in C


\

Saurabh Shukla (MySirG)


-
Agenda
-

① About C
language
② print C)
③ Write your first program .

④ Escape Sequences
⑤ Format specifiers
⑥ scanfcl
Abontclanguage
① C is a block structured
programming language
② A can
have any
number of blocks
c
program
blocks are funding
outermost
③ Usually
for identification
④ function has some name

has one function


⑤ Even the smallest C
program
be different
⑥ All function names must

must be
⑦ If there is only one function its name

main C)

⑧ If there than function the


are more one in
program
all function must be main
then name
? one .
About c.
language
-
-

⑨ You can write declaration statements


inside a block ( function ] or outside
all functions .

④ Local variables vs Global variables

statements reside only


④ Action can

inside the block (function )


sensitive language .

④ C is a case
lowercase
int a

5 ;
error
A-
← uppercase
← Global variable
int x
;
Global declaration
main c)
{ ← local variable
int a ;
Local declaration

f- I C)

{ Local variable
int b ; ←
Local declaration

}
Acticnstatement
① Input & output instructions

② Arithmetic Instruction

③ Control Instruction
standardt-nputos-outputdevikey.to
ard → standard Input
device
output
device

_%
_ogg• '

µ g.
standard output ÷
Monitor → .

device

aa•←§¥÷É
:/ .*Éd÷
-

↑:#

in
/
output device Input
device
§ LCMC )

{

LCMCI ;

=
'

LCMC ≥
,

3
Output Instruction
#

print f- C) → predefined function


text the monitor
is used to print on
printfc
some
)
.

"
) ;
"

-78
print Hello pointfc ,

{
pnntfc ) I
① to
print text
value variable
of
or
② to print a
y
an expression .

You can call a function any number of


times
but can define only once
Write a
program
to print welcome

on the screen .

include < stdio.tn >


#

int Maine )
{
);
"
"
f- ( welcome
print
return 0 ;

}
Write a
program
to print welcome on

the screen .

tt= include < stdio.tn >

int Maine )

{
f- (
"
welcome ); "

print

return 0;

}
Write a
program
to print lwekcmestudents
on the screen .
Print welcome onthefi.rs#
line and students on the second line .

s
/
welcome

);
"
"
welcome
pointfc " "
);
printfc in
"

f( students );
"

print
or
)
"

In students ;
f( welcome
"

print
Write a
program
to print lwekcmestudents
on the screen .
Print welcome onthefi.rs#
line and students on the second line .

A- include - stdio.tn >


int Maino
students ) ;
''

{ "
welcomein
print /
0 ;
return
3
tscapesequences
In newline
It tab space

lb backspace
18 carriage return

if form feed
it print \
" "
\ print
' '
\ print
to value
Write a
program print
variable
of a .

# include < stdio.tn>


a
int main c)

{
int a -_ 5 ;
"

a) ;
""
5
printfl %d ,

return 0; printfca) ; wrong


pnntfc 5%5
"

}
);
" "
a
printf( a
Write to print value of
program
a

a variable .

# include < stdio.tn >


int main C)
{
int a = 5 i
"
"
d a) ;
print C /
"


,


return 0 '
Format Stony
3
Foomatspecifiersl.cl
int

% C char

% ffloat
% If double
Write printf statement to print

following on
the screen .

Consider → int a=5 10=6 ;


,
d b) ;
"

① 56 print 7C"%d % ,
a
,

② a=5 and b=6 pnntfc"a=%d and b=%d"


,qbJ
③ a- 6 & b--5 printfda-%dd-b-T.cl "
,
b
, a)
.

④ value of a is 5 and valve of bis G

⑤ Sum
of 5 and 6 is 11
"
%d=%d",a biatb) ;
⑥ 5+6=11 print 7C id + ,

"
value of Id and value atb
④ pnntfc a is

ad
"
a b) ;
is
-

, ,

%d",qb,a+b);
"

⑤ print f- ( sum of %d and %d is


Write printf statement to print

following on
the screen .

Consider → int a=5 10=6 ;


,
"

"
5 6 print f- ( %d %d a ,
b) ;
,

printfc "a=%d b) ;
"
② a=5 and b=6 b=%d and ,
a
,
"

③ a- 6 & b--5 printfc "a=%d&b=%d ,


b , a) ;

⑥ value of a is 5 and valve of bis GI expression


⑤ Sum
of 5 and 6 is 11 →
,b,a+b);
"

%d is %d a
%d and
printfl
"

of
,
sum
⑥ 5+6=11
,b ) ;
[
"

of bis %d a
is %d and value
"

print (-
value of a
,

b) ;
printfc"%d+%d=%d
"

> ,
a ,b , at
scan f- C)
scan f- C) predefined function

scant / %d .&-a) ;
"
"


address of

write a
program to calculate sum
of
two
integers .
Write to calculate sum
of
a
program
two
integers .

# include cstdio.tn >

int Maina

{ int a. b.ci
);
"

two numbers
printfc Enter
"

%d%d & a. d- b) i
" "
scan f- ( ,
-

C=a+b ;
,b , C ) ;
"
T.disi.cl
of %d and
"
a
pointfl sum ,

return 0 :

You might also like