0% found this document useful (0 votes)
22 views15 pages

Lab 5

The document discusses 7 programs written in C language. Each program demonstrates a different basic concept of C like printing strings, characters, using format specifiers etc. The output for each program is also shown.
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)
22 views15 pages

Lab 5

The document discusses 7 programs written in C language. Each program demonstrates a different basic concept of C like printing strings, characters, using format specifiers etc. The output for each program is also shown.
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/ 15

Gh u l am M ust afa Ro l l N o :202 0F -B CE - 0 36 Secti o n

Lab

U ND ERS TA NDING IDE AN D B AS I C S T RU CT U RE O F C


LA NG U AGE P r ogr am 1 :

Obj e ctive :

Wri te a p ro gr am to pr i nt “th is i s a p ro g ram” .

So ur c e Cod e :

#i ncl u de <std i o .h >

main ( )

prin tf ( "T h is i s a pr o gr am " ) ;


Out p ut :
Pa ge1 |

G hul am Mu stafa Ro l l No :20 20 F -B CE - 036 Se cti on

P r ogr am 2 :

Obj ec ti v e :

W r ti e a p r o g r am to p r i n t “th i s i s a p r o g r a m ” .

So ur c e Code :

#i ncl u d e <stdio . h >

mai n ( v o i d ) { p r intf ( "Thi s i s a progr am " ) ; }

O u tpu t :
P a ge 2 |

G hul am M ustafa Rol l N o :2 02 0F - B CE - 0 3 6 Se ctoi n

P r o g ram 3 :

Obj e cti v e :

Th e ‘pri n tf ( ) ’ func ti o n u ses a u ni qu e fo r mat fo r p ri nt i ng c o nstants


and vari able . Consi der the fol l owi ng p ro g ram :

So urc e Co de :

#i n cl u de < std i o . h >

ma i n ( voi d )
pri ntf ( "n umbe r o n e : % d " , 1);

Ou tput :
Pag e3|

Ghu l am Mustafa Ro l l No :2020F - B CE - 036 S e c ti on

P ro g r am 4 :

Obj e c ti v e :

Th e “pri n tf ( ) ” funct i o n c an be u se d to pri n t any str i ng by spe ci -


fyi ng i ts fo r m at . Co n sdi e r th e fol l o w i ng pr og r am :

Source Co de :

#i n cl u de<std i o . h >

mai n ( vo i d )

pr in tf ( " %s i s a planet " , "E ar th " ) ;


O u tput :
Pa ge 4 |

Ghu l am Mustafa Ro ll No :2 02 0F -BCE - 03 6 Se ctio n

Pr og r am 5 :

Obj ec ti ve :

Thi s w il l p ri n t “E ar th ” fo r th e fi r st ‘ % s ’ an d “Mar s ” fo r th e sec ond


one .

Sou rc e Code :

#i nc l u d e <std io . h >

mai n ( v oi d )

pr i ntf ( " %s and % s ar e pl an e ts ", "E a rth " , "M ars " ) ;
Out p ut :
Pa g e5 |

Ghul am M u stafa Ro ll No :2 0 2 0F - BCE -0 3 6 S e c t i o n

P r ogr am 6 :

Obj e ctiv e :

T hi s p rog ra m wi l l pr i nt ‘ a ’

So u r ce Co d e :

#incl ude < st d i o . h >

m ai n ( v oid )

pr i ntf ( " % c i s a c harac te r " , ' a ' );


O utpu t :
Pa g e 6 |

G hul am M ustafa Ro ll No :2 020F- B CE - 036 Se c ti on

P r o gram 7 :

O bj ectvi e :

T he outp ut o f th si pr o gr am w il l be as foll o ws : j i s pr onounced as


j ay

S ou r c e Co d e :

#i ncl ud e <std i o . h >

main ( v o i d )

pr i nt f ( " %c is pron o unced as % s " , ' j ' , "j ay " );


Out pu t :
P ag e7 |

You might also like