0% found this document useful (0 votes)
97 views

C Sample Programs

The document contains code for various C programs including: 1. Programs to print text, calculate sums and averages of numbers, find the largest of three numbers, check if a number is even or odd. 2. Programs to print patterns like pyramids, diamonds using numbers and characters. 3. Programs to find the largest/smallest of numbers using ternary operators, check if a year is a leap year using ternary operators, convert character case.

Uploaded by

logu87
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

C Sample Programs

The document contains code for various C programs including: 1. Programs to print text, calculate sums and averages of numbers, find the largest of three numbers, check if a number is even or odd. 2. Programs to print patterns like pyramids, diamonds using numbers and characters. 3. Programs to find the largest/smallest of numbers using ternary operators, check if a year is a leap year using ternary operators, convert character case.

Uploaded by

logu87
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 48

C - EXAMPLE PROGRA MS

1. Program to print text


# include <stdio.h>
# include <conio.h>
main()
{
clrscr();
printf(HELLO WELO!E "O #$%&'("H$ O!)*"E(+,);
printf(Hanam-onda Waran.al phone / 0120345267008 716790::66,);
.etch();
;
2. Program To Read Two Nm!er" And Print T#e Sm O$ Gi%en Two Nm!er".
# include <stdio.h>
# include <conio.h>
main()
{
int a8<8 sum;
clrscr ();
printf (E="E( #'L*E >O( ' ; );
scanf (?d,8@a);
printf(E="E( #'L*E >O( A ;,);
scanf(?d,8@<);
sumBaC<;
printf(+um Of DiEen "Fo =um<ers are ?d,8 sum);
.etch();
;
&. Program To A''ept Stdent Ro(( No) Mar*" in & S!+e't" and Ca('(ate Tota() A%erage and Print it.
# include <stdio.h>
# include <conio.h>
main()
{ int r8<8c8d8 tot8 aE.;
clrscr();
printf (E="E( +"*%E=" (=O ; );
scanf (?d,8@r);
printf(E="E( >$(+" +*AGE" !'(H+ ;,);
scanf(?d,8@<);
printf(E="E( +EO=% +*AGE" !'(H+;,);
scanf(?d,8@c);
printf(E="E( "H$(% +*AGE" !'(H+ ;,);
scanf(?d,8@d);
totB<CcCd;
aE.BtotI:;
printf(JnJnJtJt #$%&'("H$ O!)*"E(+ K H'='!'HO=%' JnJn,);
printf(Jt +"*%E=" (=O ; ?d 8r);
printf(Jt >$(+" +*AGE" !'(H+ ;?d 8<);
printf(Jt +EO=% +*AGE" !'(H+ ;?d 8);
printf(Jt "H$(% +*AGE" !'(H+ ;?d 8d);
printf(Jt '#E('DE !'(H+ ; ?d,8 aE.);
.etch();
;
1
,. Program To Read T#ree Nm!er" And Print T#e -igge"t O$ Gi%en T#ree Nm!er"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8c8<i.B0;
clrscr( );
printf(E="E( #'L*E >O( '/,);
scanf(?d,8@a);
printf(E="E( #'L*E >O( A/,);
scanf(?d,8@<);
print(E="E( #'L*E >O( /,);
scanf(?d,8@c);
if (a><i.)
<i.Ba ;
if(<><i.)
<i.B<;
if (c><i.)
<i.Bc;
printf (A$DDE+" O> 'AO#E D$#E= "H(EE =*!AE( $+ ?d,8<i.)
.etch( );
;
.. Program To Read A Nm!er And /ind 0#et#er T#e Gi%en Nm!er 1" E%en Or Odd.
# include <stdio.h>
# include <conio.h>
main()
{
int n8r;
clrscr();
printf(E="E( ' =*!AE( ;,);
scanf(?d,8 @n);
rBn?4;
if(rB B 0)
printf(the a<oEe .iEen num<er is eEen num<er,);
else
printf(the a<oEe .iEen num<er is odd num<er,);
.etch();
2
3. Program to a''ept a 4ear and '#e'* w#et#er t#e gi%en 4ear 1S (eap 4ear or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int L;
clrscr( );
printf(enter a Lear/,);
scanf(?d,8@L);
if(L?6BB0@ @L?900MB0NN L?600BB0);
printf(the a<oEe .iEen Lear $+ a leap Lear,);
else
2
printf(the a<oEe .iEen Lear $+ not a leap Lear,);
.etch();
;
5. 1ndi%ida( 6igit"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8c8d;
clrscr( );
printf ( Enter a tFo di.it num<er /,);
scanf ( ?d,8 @a);
<BaI90;
cBa?90;
dB<Cc;
printf (sum of indiEidual di.its of .iEen num<ers id ?,8 d);
.etch( );
;
7. Program to a''ept a t#ree digit nm!er and print t#e "m o$ indi%ida( digit".
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8c8n8 sum;
clrscr( );
printf ( Enter a "hree %i.it =um<er/);
scanf (?d,8@n);
aBnI900;
<B( (n?900)I90);
cBn?90;
sumBaC<Cc;
printf ( +um of $ndiEidual %i.its of DiEen =um<ers is ?d,8 +um);
.etch( );
;
8. Program to a''ept a nm!er and '#e'* t#e gi%en nm!er i" Arm"trong or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int n8 a8 <8 c8 d;
clrscr( );
printf ( Enter a "hree %i.it =um<er/ );
scanf (?d,8 @n);
aBnI900;
<B((nI90)?90);
cBn?90;
dBaOaOaOC<O<O< CcOcOc;
if (nB Bd)
printf ("he DiEen =um<er is 'rmstron. num<er,);
else
3
printf ("he DiEen =um<er is =ot 'rmstron. num<er,);
.etch( );
;
19. Program to print O66 nm!er" $rom 1 to 19
# include <stdio.h>
# include <conio.h>
main( )
{
int i;
clrscr( );
for (iB9; i<B90; iCB4)
printf(?dJn,8i);
.etch( );
;
11. Program to print natra( nm!er" $rom 1 to 19 in Re%er"e
# include <stdio.h>
# include <conio.h>
main( )
{
int i;
clrscr( );
for (iB90; i>B9; i33)
printf(?dJn,8i);
.etch( );
;
12. Program to print "m o$ t#e natra( nm!er" $rom 1 to 19.
# include <stdio.h>
# include <conio.h>
main( )
{
int n8sumB08i;
clrscr( );
for (iB9; i<B90; iCC)
sumBsumCi;
printf(sum of natural num<ers from 9 to 90 is ?dJn,8sum);
.etch( );
;
1&. Program to a''ept a nm!er and print mat#emati'a( ta!(e o$ t#e gi%en no.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8t;
clrscr( );
printf(Fhich ta<le u Fant/,);
scanf(?d,8@t);
for (iB9; i<B90; iCC)
4
printf(Jn?dO?dB?d,8t8i8iOt);
.etch( );
;
1,. Program to print 1 to 19 mat#emati'a( ta!(e" .
# include <stdio.h>
# include <conio.h>
main( )
{
int i8P;
clrscr( );
for (iB9; i<B90; iCC)
for(PB9;P<B90;PCC) printf(Jn
?dO?dB?d,8i8P8iOP); .etch( );
;
1.. Program to print $i!ona''i "erie" .
# include <stdio.h>
# include <conio.h>
main( )
{
int aB08<B98cB08i;
clrscr( );
printf(?d,8a);
printf(Jn?d,8<);
for (iB9; i<B90; iCC)
{ cBaC<;
printf(Jn?d,8c);
aB<;
<Bc;
;
.etch( );
;
13. Program to print nmeri' p4ramid
# include <stdio.h>
# include <conio.h>
main()
{
int i8P; clrscr( );
for(iB9;i<B5;iCC)
{ for(PB9;P<Bi;PC
C)
printf(?d,8P);
printf(Jn,);
;
.etch();
;
5
15. Program to print nmeri'a( p4ramid.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8P 8l8-B60;
clrscr( );
for(iB9;i<B7;iCB4)
{
for(lB9;l<B-;lCC)
printf( );
for(PB9;P<Bi;PCC);
printf(?d,8P);
printf(Jn,);
-B-34;
;.etch( );;
17. Program to print nmeri'a( diamond.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8P8l8n8s8-B60;
clrscr( );
for(iB9;i<B7;iCB4)
{
for(lB9;l<B-;lCC)
printf( );
for(PB9;P<Bi;PCC)
printf(Jn,);
-B-34;
; -B-C6;
for(nB2;n>B9;n3B4)
{ for(iB9;i<B-;iC
C) printf( );
for(sB9;s<n;sCC)
printf(?d,8s);
printf(Jn,);
-B-C4;
;
.etch( );
;
6
18. Program to print '#ara'ter p4ramid.
# include <stdio.h>
# include <conio.h>
main( )
{
char i8P; clrscr();
for(iBQ5;i<B20;iCC)
{
for(PBQ5;P<Bi;PCC)
printf(?c,8P);
printf(Jn,);
;
.etch( );
;
29. Program to print '#ara'ter diamond.
# include <stdio.h>
# include <conio.h>
main( )
{
char i8P8n8r;
int s8spB60;
clrscr( );
for(iBQ5;i<B25;iCB4)
{ for(sB9;s<Bsp;sC
C) printf( );
for(PBQ5;P<i;PCC)
printf(?c,8P);
printf(Jn,);
spBsp34;
; spBspC6;
for(nB2:;n>BQ5;n3B4)
{ for(sB9;s<Bsp;sC
C) printf( );
for(rBQ5;r<Bn;rCC)
printf(?c,8r);
spBspC4;
;
.etch( );
;
7
21. Program to $ind !igge"t o$ two no !4 "ing ternar4 nm!er"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8<i.;
clrscr( );
printf(enter Ealue a,);
scanf(?d,8@a);
printf(enter the Ealue of <,);
scanf(?d,8@<); <i.B(a><)R
a/<;
printf(<i..est of the .iEen num<ers $+ ?d,8<i.);
.etch();
;
22. Program to $ind !igge"t o$ $or no !4 "ing ternar4 nm!er"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8c8d8<i.;
clrscr( );
printf(enter Ealue a,);
scanf(?d,8@a);
printf(enter the Ealue of <,);
scanf(?d,8@<);
printf(enter the Ealue of c,);
scanf(?d,8@c);
printf(enter the Ealue of d,); scanf(?d,8@d); <i.B(a><)R(a>c)R
(a>d)Ra/d/(c>d)Rc/d/(<>c)R(<>d)R</d/(c>d)Rc/d; printf(<i..est
of the .iEen 6 num<ers $+ ?d,8<i.);
.etch();
;
2&. Program to print "ma((e"t o$ $or no !4 "ing ternar4 operator"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8c8d8small;
clrscr( );
printf(enter Ealue a,);
scanf(?d,8@a);
printf(enter the Ealue of <,);
scanf(?d,8@<);
printf(enter the Ealue of c,);
scanf(?d,8@c);
printf(enter the Ealue of d,); scanf(?d,8@d); smallB(a<<)R(a<c)R
(a<d)Ra/d/(c<d)Rc/d/(<<c)R(<<d)R</d/(c<d)Rc/d;
8
printf(<i..est of the .iEen 6 num<ers $+ ?d,8small);
.etch();
;
2,. Program to a''ept a 4ear and '#e'* t#e gi%en 4ear i" (eap or not !4 "ing ternar4
# include <stdio.h>
# include <conio.h>
main( )
{
int L8leap;
clrscr( );
printf(enter anL Lr,);
scanf(?d,8@L);
leapB(L?600B B0)R/(L?900MB0)R(L?6B B0)R9/0/0;
if(leapB B9)
printf( the .iEen Lear is leap Lear,);
else
printf(.iEen Lear is not leap Lear);
.etch( );
;
2.. Program to a''ept a '#ara'ter in t#e pper'a"e and print in (ower 'a"e.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch8c9;
clrscr( );
printf(enter a cha in uppercase,);
chB.etchar();
c9BchC:4;
printf(the .iEen char in loFercasecase is,);
putchar(c9);
.etch();
;
23. Program to a''ept a '#ara'ter in an4 'a"e and print in anot#er 'a"e.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch8c9;
clrscr( );
printf(enter a char in anLcase,);
chB.etchar();
if(ch>BQ5 @@ ch<B70)
c9BchC:4;
else
if(ch>B72 @@ ch<B944)
c9Bch3:4;
printf(the .iEen char in anothercase $+,);
putchar(c9);
.etch();
;
9
25. Program to natra( nm!er $rom 1 to 19 !4 "ing w#i(e (oop.
# include <stdio.h>
# include <conio.h>
main( )
{
int aB0;
clrscr();
Fhile( a<90)
{
aBaC9;
printf(?dJn,8a);
;
.etch();
;
27. Program to a''ept a "tring and print it !4 "ing t#e w#i(e (oop.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
clrscr();
printf(enter a strin.,);
Fhile(( chB.etchar( ))MBSJnS)
putchar(ch);
.etch();
;
28. Program to a''ept a "tring in pper 'a"e and print it !4 (ower 'a"e.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch8c;
clrscr();
printf(enter a strin. in upper case/,);
Fhile(( chB.etchar( ))MBSJnS)
{
cBchC:4;
putchar(c);
;
printf( is in loFer case,);
.etch( );
;
10
&9. Program to a''ept a "tring in an4 'a"e and print it !4 anot#er 'a"e .
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
clrscr( );
printf(enter a strin. /,);
Fhile(( chB.etchar( ))MBSJnS)
{
if(ch>BS'S @@ ch<BSTS)
putchar(chC:4);
else
if(ch>BSaS @@ ch<BSUS)
putchar(ch3:4);
else
putchar(ch);
;
printf( is the strin.,);
.etch( );
;
&1. Program to a''ept a "tring print ea'# word in new (ine.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
clrscr( );
printf(enter a strin. /,);
Fhile(( chB.etchar( ))MBSJnS)
{ putchar(c
h); if(chB BS
V)
printf(Jn,);
;
.etch( );
;
&2. Program to a''ept a "tring and 'ont no o$ 'apita( (etter") no. o$ "ma(( (etter" and no. o$ "pe'ia(
'#ara'ter"
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
int cB08sB08s9B0;
clrscr( );
printf(enter a strin. /,);
Fhile(( chB.etchar( ))MBSJnS)
{
11
if(ch>BS'S@@ ch>BSTS)
cBcC9;
else
if(ch>BSaS@@ ch>BSUS)
sBsC9;
else
s9Bs9C9;
;
printf( no of capital letters are ?d,8c);
printf( no of smal9 letters are ?d,8s);
printf( no of special characters are ?d,8s9);
.etch( );
;
&&. Program to a''ept an4 "ing(e digit nm!er and print it in word" .
# include <stdio.h>
# include <conio.h>
main( )
{
int n;
clrscr( );
printf(enter a num<er /,);
scanf(?d 8@n);
sFitch(n)
{
case 0/ printf(TE(O,);
<rea-;
case 9/ printf(O=E,);
<rea-;
case 4/ printf("WO,);
<rea-;
case :/ printf("H(EE,);
<rea-;
case 6/ printf(>O*(,);
<rea-;
case 5/ printf(>$#E,);
<rea-;
case Q/ printf(+$W,);
<rea-;
case 2/ printf(+E#E=,);
<rea-;
case 1/ printf(E$DH",);
<rea-;
case 7/ printf(=$=E,);
<rea-;
default/
printf(please enter the num<er <etFeen 0 and 7,);
;
.etch( );
;
12
&,. Program to print prime nm!er" !etween 1 to 199
# include <stdio.h>
# include <conio.h>
main( )
{
int n8 i8 chec-;
clrscr();
for(iB9;i<B900;iCC)
{
chec-B9;
for(nB4;n<BiI4;nCC)
if(i?nB B0)
{ chec-B
0; <rea-;
;
if(chec-B B9)
printf(Jn ?d is a prime,8i);
else
printf(Jn ?d is not a prime,8i);
;
.etch( );
;
&.. Program to a''ept two nm!er" and print "m o$ two nm!er" !4 "ing $n'tion"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8c;
clrscr();
printf(enter the Ealue for a/,)
scanf(?d,8@a);
printf(enter the Ealue for </,)
scanf(?d,8@<);
cBadd(a8<);
printf(sum of tFo num<ers is ?d,8c);
.etch( );
;
int add(int X8 int L)
{
int U;
UBXCL;
return U;
;
13
&3. Program to a''ept a nm!er and $ind $a'toria( o$ gi%en nm!er
# include <stdio.h>
# include <conio.h>
main( )
{
int n8f;
clrscr( );
printf(enter a num<er/,)
scanf(?d,8@n);
fB fact(n);
printf(factorial Ealue is ?d,8f);
.etch();
;
int fact(int n)
{
int i8 faB9;
for(iBn;i>B9;i33)
faBfaOi;
return fa;
;
&5. Program to a''ept a nm!er and '#e'* t#e gi%en nm!er Arm"trong or not
# include <stdio.h>
# include <conio.h>
main( )
{
int n8arm;
clrscr();
printf(enter anL : di.it num<er/,)
scanf(?d,8@n);
armB armstron.(n);
if(armB Bn)
printf(?d is 'rmstron. num<er,8n);
else
printf(?d not a 'rmstron. num<er,8n);
.etch( );
;
int 'rmstron. (int n)
{
int a8<8c8d; aBnI900;
<B((nI90)?90); cBn
?90;
dBaOaOaC<O<O<CcOcOc;
return d;
;
14
&7. Program to a''ept a nm!er and print t#e "m o$ gi%en and Re%er"e nm!er
# include <stdio.h>
# include <conio.h>
main( )
{
int a8<8n;
clrscr( );
printf(enter a num<er/,)
scanf(?d,8@n);
aBreE(n);
printf((E#E(+E O> ' D$#E= =*!AE( $+ ?d,8a);
<Badd(n8a);
printf(Jn sum of a .iEen and reEerse num<er is ?d,8<);
.etch( );
;
int reE( int n)
{
int r8reEB08s;
Fhile(n>0)
{ rBn?90;
reEBreEO90Cr;
nBnI90;
;
return reE;
;
int add(int n8 int a)
{
return nCa;
;
&8. Program to a''ept 19 nm!er" and print $ir"t $i%e nm!er" in origina( order and print (a"t $i%e
nm!er" in re%er"e order.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8aY90Z;
for(iB0;i<90;iCC)
{
printf(enter Ealue for aY?dZ,8i);
scanf(?d,8@aYiZ);
; for(iB0;i<B6;iCC)
printf(Jn'Y?dZB?d,8i8aYiZ);
for(iB7;i>B5;i33)
printf(Jn'Y?dZB?d,8i8aYiZ);
.etch( );
;
15
,9. Program to a''ept a "tring and print t#e re%er"e o$ t#e gi%en "tring !4 "ing $or (oop.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8P;
char nameY10Z;
clrscr( );
printf( enter a strin.,);
.ets(name);
for(iB0;i<10 @@ ((name YiZB .etchar())MBSJnS);iCC);
if(nameYiZB BSJnS)
nameYiZBSJ0S;
for(PBi;P>B0;P33)
putchar(nameYPZ);
printf(is the reEerse of .iEen strin.,);
.etch( );
;
,1. Program to a''ept a "tring and '#e'* t#e gi%en "tring i" pa(indrome or not .
# include <stdio.h>
# include <conio.h>
main( )
{
int i8lim8c8chec-B9;
char FordY10Z;
clrscr( );
printf( enter a strin.,);
for(iB0;i<10 @@ ((Ford YiZB .etchar())MBSJnS);iCC);
limBi39; cBlimI4;
for(iB0;i<B0;iCC8lim33)
if(FordYiZMB FordYlimZ)
{
chec-B0;
<rea-;
;
if(chec-B B9)
printf(the .iEen strin. is palindrome );
else
printf( not palindrome,);
.etch( );
;
16
,2.Program to a''ept %a(e" into & dimen"iona( arra4 and print .
# include <stdio.h>
# include <conio.h>
main( )
{
int aY:ZY:Z8i8P;
clrscr( );
for(iB0;i<B4;iCC)
for(PB0;P<B4;PCC)
{
printf( enter the Ealue for aY?dZY?dZ /,8i8P);
scanf(?d,8@aYiZYPZ);
;
for(iB0;i<B4;iCC)
{ for(PB0;P<B4;PCC)
printf( ?d/,8aYiZYPZ);
printf(VJn,);
;
.etch( );
;
,&. Program to print pper triang(e .
# include <stdio.h>
# include <conio.h>
main( )
{
int aY6ZY6Z8i8P8c;
clrscr( );
printf( enter Fhich no u Fant,);
scanf(?d,8@c);
for(iB0;i<6;iCC)
for(PB0;P<6;PCC)
if(i<P)
aYiZYPZBc;
else aYiZYPZB0;
for(iB0;i<6;iCC)
for(PB0;P<6;PCC)
{
printf( ?d/,8aYiZYPZ);
printf(VJn,);
;
.etch( );
;
17
,,. Program to a''ept two & dimen"iona( arra4 and "tore addition o$ t#o"e into arra4" into t#e t#ird
arra4 .
# include <stdio.h>
# include <conio.h>
main( )
{
int aY:ZY:Z8<Y:ZY:Z8cY:ZY:Z8i8P;
clrscr( );
for(iB0;i<:;iCC)
for(PB0;P<:;PCC)
{
printf(enter the tFo Ealues for aY?dZY?dZ @ <Y?dZY?dZ,8 i8P8i8P);
scanf(?d?d,8@aYiZYPZ8@<YiZYPZ);
;
for(iB0;i<:;iCC)
{
for(PB0;P<:;PCC)
{ cYiZYPZBaYiZYPZC<YiZ
YPZ; printf(?d,8cYiZ
YPZ);
;
printf(Jn,);
;
.etch( );
;
,.. Program to a''ept a "tring and $ind t#e (engt# o$ t#e gi%en "tring !4 "ing $n'tion"
# include <stdio.h>
# include <conio.h>
int .etline(char strYZ);
main( )
{
char strY10Z;
int len.th;
clrscr( );
printf( enter a strin.,);
len.thB.etline(str);
printf(len.th of the .iEen strin. is ?d,8len.th);
.etch ( );
;
int .etline(char strYZ)
{
int i;
for(iB0;i<10@@((strYiZB.etchar( ))MBSJnS); iCC);
if(strYiZB BSJnS)
strYiZBSJ0S;
return i;
;
18
,3. Program to 'ont t#e nm!er o$ word") '#ara'ter") a(p#a!et") %owe(") 'on"onant" and digit in a (ine
o$ text.
#include<stdio.h>
#include<conio.h>
main( )
{
int noaB08no<B08nocB08noEB08noFB08nochB08l8$;
char ch8sY900Z;
clrscr( );
printf(enter 4 lines of teXt,);
.ets(s);
lBstrlen(s);
for(iB0;i<9;iCC)
{
sFitch(sYiZ)
{
case VaS/
case VeS/
case ViS/
case VoS/
case VuS/
case V'S/
case VES/
case V$S/
case VOS/
case V*S/
noECC;
<rea-;
;
if(isalpha(sYiZ))
noaCC;
if(isdi.it(sYiZ))
nodCC;
if(noaYiZBBS V) @@ (noaYiC9ZMBS V)
noFCC;
;
nochBl3no<;
nocBnoa3noE;
printf(total no of Fords ?d,8noF);
printf(total no of characters(Fithout <lan-s)?d,8noch);
printf(total no of characters(includin. <lan-s)?d,8l);
printf(total no of alpha<ets ?d,8noa);
printf(total no of EoFels ?d,8noE);
printf(total no of characters ?d,8noc);
printf(total no of di.its ?d,8nod);
.etch( );
;
19
,5. Program to a''ept two "tring and 'ompare t#e "tring" are e:a( or not
# include <stdio.h>
# include <conio.h>
int .etline (char lineY Z8 int lim );
int strc(char str9Y Z8 char str4YZ );
main( )
{
char str9Y10Z8str4Y10Z;
int comp;
clrscr( );
printf(enter first strin./,);
.etline(str9810);
printf(enter second strin./,);
.etline(str4810);
compBstrc(str98str4);
if(comp>0)
printf(first strin. is <i..er,);
else
if(compBB0)
printf(<oth the strin.s are e[ual,);
.etch( );
;
int .etline(char strYZ8 int lin)
{
int i; for(iB0;i<lin@@((strYiZB.etchar())M
BSJnS);iCC); if(strYiZBSJ0S)
return i;
;
int strc(char str9YZ8char str4YZ)
{
int i;
for(iB0;str9YiZ;iCC)
if(str9YiZMBstr4YiZ)
return str9YiZ3str4YiZ;
return str9YiZ3str4YiZ;
;
,7. Program to "ort t#e entered nm!er" "ing !!!(e "ort.
# include <stdio.h>
# include <conio.h>
main( )
{
int aY900Z8i8P8n8t;
clrscr( );
printf(enter the arraL siUe,);
scanf(?d,8@n);
for(iB9;i<n;iCC)
scanf(?d,8@aYiZ);
for(iB9;i<Bn;iCC)
for(PBiC9;P<n;PCC)
20
if(aYiZ>aYPZ)
{ tBaYiZ
aYiZBaYPZ;
aYPZBt;
;
printf(the sorted elements are );
for(iB9;i<Bn;iCC)
print(?d,8aYiZ);
.etch( );
;
,8. Program to read date)mont#) 4ear and print t#e next da4;" date)mont#)4ear.
# include <stdio.h>
# include <conio.h>
main( )
{
int monthY94ZB{:98418:98:08:98:08:98:98:08:98:08:9;;
int d8m8L8nd8nm8nL8ndaLs;
clrscr( );
printf(enter the date8month8Lear,);
scanf(?d?d?d,8@d8@m8@L);
ndaLsBmonthYm39Z;
if(mBB4)
{
if(L?900BB0)
{ if(L
?600BB0)
ndaLsB47;
; else if(L
?6BB0)
ndaLsB47;
;
ndBndC9;
nmBm;
nLB L;
if(nd>ndaLs)
{ ndB9
; nmC
C;
;
if(nm>94)
{ nmB
9; nLC
C;
;
printf(DiEen date is ?d/?d/?dJn,8d8m8L);
printf(neXt daLs date is ?d/?d/?d,8nd8nm8nL);
.etch( );
;
21
.9. Program to inter'#ange two %a(e" "ing pointer".
# include <stdio.h>
# include <conio.h>
Eoid interchan.e(int OX8int OL);
main( )
{
int a8<;
clrscr( );
printf(enter Ealues of a and <,);
scanf(?d?d,8@a8@<);
interchan.e(@a8@<);
;
Eoid interchan.e(X8L)
int OX8OL;
{
int t;
tBOX;
OXBOL;
OLBt;
printf(?dBX8 ?dB L,8OX8OL);
.etch( );
;
.1. Program to print <PASCAL TR1ANGLE=.
#include<stdio.h>
#include<conio.h>
main()
{
int n8pB98[8num8sp;
clrscr( );
printf(enter the num<er of roFs,);
scanf(?d,8@n); for(pB0;p<Bn;pC
C)
{
for(spB9;sp<B603(:Op);spCC)
printf( );
for([B0;[<n;[CC)
{ if(([BB[)NN
([BB0)) numB9;
else
numBnumO(([3[)C9)I[;
printf(?4d,8num);
printf(Jn,);
;;
.etch( );
;
22
.2. Program to '#e'* w#et#er a gi%en nm!er i" per$e't or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8n8sB0;
clrscr();
printf(enter the num<er,);
scanf(?d,8@n);
for(iB9;i<nI4;iCC) if(n
?iBB0)
sCBi;
if(sB Bn)
printf(the num<er is perfect no,);
else
printf(the num<er is not perfect );
.etch( );
;
.&. Program to '#e'* w#et#er a gi%en nm!er i" prime nm!er.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8n8cB0;
clrscr( );
printf(enter a num<er,);
scanf(?d,8@n);
for(iB0;i<Bn;iCC) if(n
?iBB0)
cCC;
if(cBB4)
printf(.iEen num<er is a prime num<er,);
else
printf(.iEen num<er is not prime num<er,);
.etch( );
;
.,. Program to read >n; nm!er and print t#em in matrix term" in a(( order".
# include <stdio.h>
# include <conio.h>
main( )
{
int i8n8c8p8[8r8-8aY40Z;
clrscr();
printf(enter the arraL siUe,);
scanf(,?d,8@n);
printf(enter the elements,);
for(iB9;i<Bn;iCC)
scanf(?d,8@aYiZ);
iB9;
Fhile(i<Bn)
23
{
if(n?iBB0)
{ rBi;
cBnIi;
-B9;
for(pB9;p<Br;pCC)
{ for([B9;[<Bc;[CC)
printf(?d,8aY-CCZ)
printf(Jn,);
;
iCC;
.etch( );
;
... Program to "ear'# an e(ement "ing !inar4 "ear'#
# include <stdio.h>
# include <conio.h>
main( )
{
int aY900Z8i8n8X8 mid8 top8 <ot8c;
clrscr();
printf(enter the arraL siUe;,);
scanf(?d,8@n);
printf(enter the arraL elements,);
for(iB9;i<Bn;iCC)
scanf(?d,8@aYiZ);
topB9;
<otBn;
cB0;
printf(enter the element to searched,);
scanf(?d,8@X);
Fhile((top <B<ot)@@(cBB0))
{ midB(topC<ot)I
4; if(aYmidZ<X)
topBmidC9;
else
if(aYmidZ>X)
<otBmid39;
else
cB9;
;
if(cBB9)
printf(elements is at position;?d,8mid);
else
printf(elements is not in list,);
.etch( );
;
24
.3. Program to a''ept two nm!er" and print t#e "m o$ gi%en two nm!er" !4 "ing pointer"
# include <stdio.h>
# include <conio.h>
main( )
{
int a8 <8c;
clrscr( );
aB90;
<B40;
cBO(@a)CO(@<);
printf(?d,8c);
.etch( );
;
.5. Program" to m(tip(4 two Matri'e"
# include <stdio.h>
# include <conio.h>
main( )
{
int aY90ZY90Z8<Y90ZY90Z8cY90Z8Y90Z8i8P8m8n8p8[8-;
clrscr( );
printf(enter the siUe of first matrices,);
scanf(?d?dS8@m8@n);
printf(enter the siUe of second matriX,);
scanf(?d?dS8@p8@[);
if(nBBp)
{
printf(enter first matrices elements,);
for(iB9;i<m;iCC)
for(PB9;P<n;PCC)
scanf(?d,8@aYiZYPZ);
printf(enter second matri X elements,);
for(iB9;i<p;iCC)
for(PB9;P<[;PCC)
scanf(?d,8@<YiZYPZ);
for(iB9;i<m;iCC)
for(PB9;P<n;PCC)
{
cYiZYPZB0; for(-B9;-<n;-CC)
cYiZYPZBcYiZYPZCaYiZY-ZO<Y-ZYPZ;
;
printf(the multiplication matriX is,);
for(iB9;i<m;iCC)
{ for(PB9;P<n;PCC)
print(?4d,8cYiZYPZ);
printf(Jn,);
;
;
else
25
printf(multiplication is not possi<le,);
.etch( );
;
.7. Program to print prime nm!er !etween 1-199
# include <stdio.h>
# include <conio.h>
main( )
{
int i8n8c; clrscr( );
for(nB9;n<B900;nCC)
{
cB0;
for(iB9;i<Bn;iCC)
if(n?iBB0)
cCC; if(cBB4)
printf(Jn?d,8n);
;
.etch( );
;
.8. Program to a''ept a "tring and $ind t#e (engt# o$ t#e "tring
# include <stdio.h>
# include <conio.h>
main( )
{
char nameY10Z;
int i;
clrscr( );
printf(enter a strin. ;,);
for(iB0;i<10@@((nameYiZB.etchar( ))MBSJnS);iCC);
printf(?d is the siUe of strin.,8i);
.etch( );
;
39. Program to $i!ano''i o$ matrix
# include <stdio.h>
# include <conio.h>
# include <math.h>
main( )
{
int aY90ZY90Z8i8P8m8n sumB0;
float norm;
clrscr( );
printf(Venter the matriX siUe,);
scanf(?d?d,8@m8@n);
printf(enter the element of matriX,);
for(iB9;i<Bm;iCC)
for(PB9;P<Bn;PCC)
26
{ scanf(?d,8@aYiZYPZ);
sumBsumC(aYiZYPZOaYiZYPZ)
; normBs[rt(sum);
printf(normB?f,8norm);
.etch( );
;
31. Program a "tr'tre w#i'# read" >n; "tdent" in$ormation ?name)& "!+e't" mar*"@ and 'a('(ate
tota( mar*") re"(t print t#em in a parti'(ar $ormat.
# include <stdio.h>
# include <conio.h>
main( )
{
struct student
{
char nameY40Z;
int m98m48m:8 tot;
char resultY90Z;
;studY90Z;
int i8n;
clrscr( );
printf(enter no of students Jn,);
scanf(?d,8@n);
for(iB0;i<n;iCC)
{
printf(,enter ?d student deatails Jn,8i);
printf(,enter nameJn,); scanf(?s,8
studYiZ.name); printf(enter mar-s of
: su<Pects Jn,);
scanf(?d?d?d,8 @[email protected]@studYiZ.m:);
studYiZ.totBstudYiZ.m9CstudYiZ.m4CstudYiZ.m:;
if((studYiZ.m9>:5)@@(studYiZ.m4>:5)@@(studYiZ.m:>:5))
strcpL(studYiZ.result8,pass,);
else
strtcpL(studYiZ.result8,fail,)
;
;
clrscr( );
printf(name total result Jn,);
for(iB0;i<n;iCC)
{
printf(?s ?d ?s Jn,8 studYiZ.name8studYiZ.tot8studYiZ.result);
;
.etch( );
;
32. Program to $ind w#et#er a ":are matrix i" a@ "4mmetri' !@ "*ew "4mmetri' '@ none o$ two.
# include <stdio.h>
# include <conio.h>
main( )
{
int aY90ZY90Z8i8P8m8n8cB08c9B0;
27
clrscr( );
printf(enter the arraL siUe,);
scanf(?d,8@n);
printf(enter the elements,);
for(iB9;i<Bm;iCC)
for(PB9;P<Bn;PCC)
scanf(?d,8@aYiZYPZ);
for(iB9;i<Bm;iCC)
for(PB9;P<Bn;PCC)
{
if(aYiZYPZBBaYPZYiZ)
cB9; else if(aYiZ
YPZBBaYPZYiZ) c9B9;
;
printf(the .iEen matriX is Jn,);
for(iB9;i<Bm;iCC)
{ for(PB9;P<Bn;PCC)
printf(?6d,8aYiZYPZ);
printf(Jn,);
;
if(cBB0)
printf(the .iEen matriX is sLmmetric,);
else
if(c9BB0)
printf(the matriX is s-eF sLmmetric,);
else
printf(none of tFo,);
;
.etch( );
;
3&. Program to $ind area o$ a triang(e w#en t#ere "ide" are gi%en.
# include <stdio.h>
# include <conio.h>
main( )
{ int
a8<8c; float
s8 area;
clrscr( );
printf(enter there sides of the trian.le,);
scanf(?d?d?d,8@a8@<8@c);
if((aC<)<cNN(<Cc)<aNN(aCc)<<)
printf(findin. area is not possi<le,);
else
sB(aC<Cc)I4;
areaBs[rt(sO(s3a)O(s3<)O(s3c));
printf(areaB?.4f,8area);
.etch( );
;
28
3,. Program to print Arm"trong nm!er !etween 1-.99.
#include<stdio.h>
#include <conio.h>
main( )
{
int i8n8s8r; clrscr( );
for(iB9;i<B500;iCC)
{
nBi; sB0;
Fhile(n>0)
{ rBn?90;
sBsC(rOrOr);
nBnI90;
;
if(iBBs)
printf(Jn?d,8s);
;
.etch();
;
3.. Program to '#e'* w#et#er a gi%en nm!er i" Arm"trong or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int i8n8s8r8-;
clrscr( );
printf(enter a num<er,);
scanf(?d,8@n);
-Bn; sB0;
Fhile(n>0)
{ rBn?90;
sBsC(rOrOr);
nBnI90;
;
if(-BBs)
printf(.iEen num<er is 'rmstron. ?d,8-);
else
printf(.iEen num<er is not 'rmstron. ?d,8-);
;
.etch();
;
33. Program to print t#e $(o4d;" triang(e.
# include <stdio.h>
# include <conio.h>
main( )
29
{
int i8n8s8r -B9;
clrscr( );
printf(enter a num<er of roFs,);
scanf(?d,8@n); for(iB9;i<Bn;iC
C)
{
for(sB9;s<B603i;sCC)
printf( ,);
for(PB9;P<Bi;PCC)
printf(?:d,8-CC);
printf(Jn,);
;
.etch( );
;
35. Program to read data in & "tr'tre" and print
# include<stdio.h>
# include<conio.h>
main( )
{
struct <oo-
{
char code;
int piece;
float price;
;;
struct <oo- <98<48<:;
main( )
{
clrscr( );
printf(enter code8piece8price,); scanf(?c?d
?f,8@<9.code8@<9.piece8@<9.price); printf(enter
code8piece8price,); scanf(?c?d
?f,8@<4.code8@<4.piece8@<4.price); printf(enter
code8piece8price,); scanf(?c?d
?f,8@<:.code8@<:.piece8@<:.price); printf(the
details are,);
printf(Jn ?c?d?f,8<9.code8<9.piece8<9.price);
printf(Jn ?c?d?f,8<4.code8<4.piece8<4.price);
printf(Jn ?c?d?f,8<:.code8<:.piece8<:.price);
.etch( );
;
37. Program to print a diagona( matrix.
#include<conio.h>
#include<stdio.h>
main()
{
int aY6ZY6Z8i8P;
clrscr( );
30
for(iB0;i<6;iCC)
for(PB0;P<6;PCC)
if(iBBP)
cYiZYPZB2;
else aYiZ
YPZB0;
for(iB0;i<6;iCC)
{ for(PB0;P<6;PCC)
printf(?d,8aYiZYPZ);
printf(Jn,);
;
.etch();
;
38. Program to 'op4 'ontent" o$ one $i(e into anot#er.
#include<stdio.h>
#include<conio.h>
main( )
{
>$LE Ofp98Ofp4; char ch;
fp9Bfopen(teXt9,8,F,);
printf(Venter the teXt,);
Fhile((chB.etchar( ))MBEO>)
putc(ch8fp9);
fclose(fp9);
fp9Bfopen(teXt9,8,r,);
fp4Bfopen(teXt4,8,F,);
Fhile((chB.etc(fp9))MBEO>)
putc(ch8fp4);
fclose(fp4);
.etch( );
;
59. Program to 'reate a $i(e o$ nm!er and 'op4 odd nm!er into "e'ond $i(e and e%en nm!er into
t#ird $i(e.
#include<stdio.h>
#include<conio.h>
main( )
{
>$LE Ofp98Ofp48Ofp:; int i;
fp9Bfopen(%'"'9,8,F,);
printf(enter the num<er,);
scanf(?d,8@i); Fhile(iM
Beof( ))
{
putF(i8fp9);
; fcolse(fp9);
fp9Bfopen(%'"'9,8,r,);
fp4Bfopen(%'"'4,8,F,);
31
a@ a@ Print t#e #ote(" o$ gi%en grade in order o$ room'#ange.
!@ !@ Print t#e #ote(" wit# room'#ange (e"" t#an a gi%en '#ange.
fp:Bfopen(%'"':,8,F,);
Fhile((iB.etF(fp9))M
BEO>()) if(i?4B B0)
putF(i8fp:);
else
putF(i8fp4);
fcolse(fp9);
fcolse(fp4);
fcolse(fp:);
.etch( );
;
51. Program a "tr'tre w#i'# "tore" in$ormation a!ot #ote(" w#i'# "tore" in$ormation a!ot name)
grade) room '#ange) no o$ room".
#include<stdio.h>
#include<conio.h>
main( )
{
struct hotel
{
char nameY40Z;
char citLY90Z;
char .rade;
int rc8nr;
;;
struct hotel htY40Z8t;
int i8n8P8c;
char .r;
clrscr( );
printf(enter no. of hotelsJn,);
scanf(?d,8@n);
for(iB0;i<n;iCC)
{
printf(enter name of hotel Jn,);
scanf(?s,[email protected]);
printf(enter name of citL Jn,);
scanf(?s,[email protected] L);
printf(enter the .rade Jn,);
scanf(?s,.htYiZ..rade);
htYiZ..radeB.etche( );
printf(enter room char.e Jn,);
scanf(?d,[email protected]);
printf(enter no of rooms Jn,);
scanf(?d,[email protected]);
; for(iB0;i<n;iCC)
for(PB0;P<n3i;PCC)
{ tBhtYPZ;
htYPZBhtYPCiZ;
htYPC9ZBt;
;
32
printf(enter a .rade to print the hotels Jn,);
.rB.etche();
clrscr();
printf(hotel name citL .rade roomchar.e no of room,);
for(iB0;i<n;iCC)
if(.rBBhtYiZ..rade)
printf(?s ?s ?c ?d ?d,8htYiZ. name8htYiZ.citL8htYiZ..rade8htYiZ.rc8htYiZ.nr);
.etch();
printf(enter a room char.e to print hotels less than .iEen char.e Jn,);
scanf(?d,8@c);
printf(hotel name citL .rade roomchar.e no of rooms,);
for(iB0;i<n;iCC)
if(c<BhtYiZ.rc)
printf(?s ?s ?c ?d ?d,8htYiZ.name8htYiZ.citL8hYiZ..rade8htYiZ.rc8htYiZ.nr);
;
52. Program w#i'# doe" t#e !e(ow pro'e"" a$ter reading on odd no o$ integer.
a@ a@ Print t#em in gi%en order.
!@ !@ Rep(a'e "e'ond e(ement" !4 prod't o$ $ir"t and (a"t e(ement
'@ '@ Rep(a'e midd(e %a(e !4 a%erage o$ a(( e(ement".
d@ d@ Rep(a'e a(( A%e no;" !4 Bero;".
#include<stdio.h>
#include<conio.h>
main( )
{
int aY90Z8i8n8sumB0;
clrscr( );
printf(enter the arraL siXe );
scanf(?d,8@n);
printf(enter the elements,);
for(iB0;i<n;iCC)
{
scanf(?d,8@aYiZ);
sumBsumCaYiZ;
;
printf("he .iEen arraLs is/ );
for(iB0;i<n;iCC)
printf(?d,8aYiZ);
aY4ZBaY9ZOaYn39Z;
printf(Jn the .iEen areaL after replacin. 4nd element is,);
for(iB0;i<n;iCC)
printf(?d,8aYiZ);
aY(9CnI4)ZBsumIn;
printf(Jn the .iEen arraL after replacin. middle element <L aEera.e of all,);
for(iB0;i<n;iCC)
if(aYiZ<0)
aYiZB0;
printf(Jn .iEen arraL after replacin. KEe Ealues <L Uero,);
for(iB0;i<n;iCC)
printf(?d,8aYiZ);
printf(Jn,);
.etch();
;
33
5&. Program to "ort t#e entered e(ement" "ing "e(e'tion "ort te'#ni:e.
#include<stdio.h>
#include<conio.h>
main( )
{
int aY900Z8i8n8P8t8min8pos;
clrscr();
printf(enter the arraL siUe,);
scanf(?d,8@n);
printf(enter the elements,);
for(iB0;i<n;iCC)
scanf(?d,8@aYiZ);
for(iB0;i<n;iCC)
{
minBaYiZ;
posBi;
for(PB0;P<n39;PCC)
if(min>aYPZ)
{ min
BP;
posBP;
; tBaYiZ;
aYiZBaYposZ;
aYposZBt;
;
printf(the sorted elements are,);
for(iB0;i<n;iCC)
printf(?4d,8aYiZ);
.etch( );
;
5,. Program to $ind w#et#er a nm!er i" di%i"i!(e !4 >11; or not wit#ot a'ta( di%i"ion.
#include<stdio.h>
#include<conio.h>
#include<math.h>
main( )
{
int a8<8n8eEensumB08oddsumB08diE;
clrscr( );
printf(enter a num<er,);
scanf(?d,8@n);
aBn;
<BnI90;
Fhile(a>0)
{ oddsumBoddsumC(a
?90); aBaI90;
;
Fhile(<>0)
34
{ eEensumBeEensumC(<
?90); <B<I90;
;
diEBa<s(eEensum3oddsum);
if(diE?99BB0)
printf("he num<er is diEisi<le <L 99,);
else
printf("he num<er is not diEisi<le <L 99,);
.etch();
;
5.. Program to $ind maximm and minimm o$ entered ;n; nm!er "ing arra4".
#include<stdio.h>
#include<conio.h>
main( )
{
int i8n8aY90Z8min8maX;
clrscr( );
printf( enter hoF manL num<er,);
scanf(?d,8@n);
printf(enter the elements,);
for(iB0;i<n;iCC)
scanf(,?d,8@aYiZ);
minBaY0Z;
for(iB0;i<n;iCC)
if(min>aYiZ)
minBaYiZ;
printf(minimumB?d,8min);
maXB0;
for(iB0;i<n;iCC)
if(maX<aYiZ);
maXBaYiZ;
printf(Jn maXimumB?d,8maX);
.etch( );
;
53. Program to print t#e $o((owing "erie" nti( t#ere "m ex'eed" 2.3 term %a(e ex'eed" 1..
xCx2D2ECx&D&EC------------.
#include<stdio.h>
#include<conio.h>
main( )
{
float X8sumB08prodB9;
int i;
clrscr( );
printf(enter X Ealue,);
scanf(?fS8@X); iB9;
Fhile((sum<4.Q)@@(prod<B9.5))
{
prodBprodO(XIi);
35
if(prod<B9.5)
sumBsumCprod;
if(sum>4.Q)
{
sumBsum3prod;
<rea-;
; printf(sumB;
?fS8sum); iCC;
;
.etch( );
;
55. Program to print a $re:en'4 di"tri!tion ta!(e $or a '(a"" o$ 29-"tdent" in t#e $o((owing $ormat.
T#e mar*" range $orm 1-2..
'(a"" intert%a( $re:en'4
1-. 1-. -
3-19 3-19 -
11-1. 11-1. -
13-29 13-29 -
21-2. 21-2. -
#include<stdio.h>
#include<conio.h>
main( )
{
int aY40Z8i8n9B08n4B08n:B08n6B08n5B0;
clrscr();
printf(enter the anL 40 no of ran.e(9345));
for(iB9;i<B40;iCC)
scanf(?d,8@aYiZ);
for(iB9;i<B40;iCC)
if((aYiZ>B9)@@(aYiZ<Q))
n9CC;
else
if((aYiZ>5)@@(aYiZ<99))
n4CC;
else
if((aYiZ>90)@@(aYiZ<9Q))
n:CC; else
if((aYiZ>95)@@(aYiZ<49))
n6CC;
else
if((aYiZ>40)@@(aYiZ<4Q))
n5CC;
printf(class interEal fre[uencL,);
printf(Jn 935 ?d,8n9);
printf(Jn Q390 ?d,8n4);
printf(Jn 99395 ?d,8n:);
printf(Jn 9Q340 ?d,8n6);
printf(Jn 49345 ?d,8n5);
.etch();
;
36
57. Program to a''ept %a(e" into an arra4 and print arra4 in re%er"e and origina( $ormat !4 "ing t#ree
di$$erent $n'tion".
#include<stdio.h>
#include<conio.h>
Eoid read\arraL(int XYZ);
Eoid print\arraL(int LYZ);
Eoid reE\arraL(int UYZ);
main()
{
int aY5Z;
clrscr();
read\arraL(a);
printf\arraL(a);
reE\arraL(a);
.etch( );
;
Eoid read\arraL(int XYZ)
{
int i;
for(iB0;i<B6;iCC)
{
printf(enter Ealues for aY?dZ/,8i);
scanf(?d,8@XYiZ);
;
;
Eoid print\arraL(int LYZ)
{
int i;
for(iB0;i<B6;iCC)
printf(?d,8LYiZ);
;
Eoid reE\arraL(int UYZ)
{
int i;
for(iB6;i>B0;i33)
printf(Jn?d,8UYiZ);
;
58. Program to a''ept %a(e" into "ing(e dimen"iona( arra4 and print t#e arra4 in re%er"e !4 "ing
pointer".
#include<stdio.h>
#include<conio.h>
main( )
{
int aY5Z8O<8i;
clrscr( );
<B@aY0Z;
for(iB0;i<B6;iCC)
{
37
printf(enter a Ealue for aY?dZ;,.i);
scanf(?d,8<);
<CC;
; <B@aY6Z;
for(iB0;i<B6;iCC)
{ printf(Jn
?d,8O<); <33 ;
;
.etch( );
;
79. Program to read a "tring and print t#e nm!er o$ '#ara'ter" in ea'# word o$ t#e "tring.
#include<stdio.h>
#include<conio.h>
#include<strin..h>
main( )
{
char sY900Z;
int i8l8ncB0;
clrscr( );
printf(enter the stin.,);
.ets(s);
lBstrlen(s);
for(iB0;i<l;iCC)
{
if(sYiZMBS V)
{ ncB0;
Fhile(sYiZMBS V)
{
ncCC;
printf(?c,8sYiZ);
iCC;
if(sYiZBSJ0S)
<rea-;
;
printf(JtJt ?d,8nc);
printf(Jn,);
;
;
.etch();
;
38
71. Program to a''ept two "tring" and 'ompare t#o"e two "tring"
#include<stdio.h>
#include<conio.h>
int strcomp (char Opt98 char Opt4);
Eoid read3strin.(charOpt);
main( )
{
char line Y10Z8line4Y10Z;
clrscr( );
printf(enter first strin.;,);
read3strin. (line9);
printf(enter second strin.,);
read3strin.(line4);
if(strcomp (line98line4)>0)
printf(second strin. <i..est,);
else
if(strcomp (line98line4)>0)
printf( first strin. <i..est;,);
else
printf(<oth the strins are e[ual,);
.etch( );
;
Eoid read3strin.(charOpt)
{
for(;(OptB.etchar( ))MBSJnS;ptCC);
OptBSJ0S;
;
int strcomp (char Opt98 char Opt4)
{ for(;Opt9MBSJ0S;pt9CC;pt4C
C) if(Opt9MBOpt4)
<rea-;
return Opt93Opt4;
;
72. Program to a''ept a "tring "ing pointer" and $n'tion".
#include<stdio.h>
#include<conio.h>
main( )
{
int chY40Z;
clrscr ( );
printf(enter a strin.,);
read\arraL(ch);
printf(?s,8ch);
.etch( );
;
Eoid read\strin. (charOpt)
{
for(;(OptB.etchar( ))MBSInS;ptCC);
OptBSJ0S;
;
39
7&.Program to read a "tring and print t#e $ir"t two '#ara'ter" o$ ea'# word in t#e "tring.
#include<stdio.h>
#include<conio.h>
main( )
{
char sY900Z;
int i8l;
clrscr( );
printf(enter a strin.,);
.ets(s);lBstrlen(s);
for(iB0;i<l;iCC)
{
if(sYiZMBS V @@ sYiZBS V)
{
printf(?c ?c,8sYiZ8sYiC9Z)
iBiC4;
Fhile(sYiZMBS V)
iCC;
;
;
.etch( );
;
7,.Program to a''ept two nm!er" and print t#e "m o$ gi%en two nm!er" !4 "ing pointer"
#include<stdio.h>
#include<conio.h>
main( )
{
int a8 <8c;
clrscr( );
aB90;
<B40;
cBO(@a)CO(@<);
printf(?d,8c);
.etch( );
;
7..Program to a''ept a "tring and print re%er"e o$ t#e gi%en "tring !4 "ing $n'tion".
#include<stdio.h>
#include<stdio.h>
int .etline (char strYZ);
Eoid printline (char strYZ8int i);
main( )
{
char strY10Z;
int 9;
clrscr( );
9B.etline(str );
printline(str89);
printline(str89);
40
.etch ( );
;
int .etline(char strYZ)
{
int 9;
printf(enter a strin.;,);
for(iB0;i<10@@((strYiZB.etchar())MBSJnS);iCC);
if(strYiZBSJ0S;
return i;
;
Eoid printline(char strYZ8int 9)
{
int P;
for(PB9;P<B0;P33)
printf(?c,8strYPZ);
printf(Vis the reEefrse strin.,);
;
73. Program to a''ept two & dimen"iona( arra4 and "tore "!tra'tion o$ t#o"e two arra4" into t#ird
arra4..
#include<stdio.h>
#include<conio.h>
main( )
{
int aY:ZY:Z8<Y:ZY:Z8cY:ZY:Z8i8P;
clrscr( );
for(iB0;i<:;iCC)
for(PB0;P<:;PCC)
{
printf(enter tFo Ealues for aY?dZY?dZ @ <Y?dZY?dZ/,8i8P8i8P);
scanf(?d?d,8@aYiZYPZ8@<YiZYPZ);
;
for(iB0;i<:;iCC)
{
for(PB0;P<:;PCC)
{
cYiZYPZBaYiZYPZ3<YiZYPZ;
printf(?d,88cYiZYPZ);
;
printf(Jn,);
;
.etch( );
75.Program to a''ept a "ing(e dimen"iona( arra4 and print t#em !4 "ing pointer"
#include<stdio.h>
#include<conio.h>
main( )
{
int aY5Z8O<8i;
clrscr( );
<B@aY0Z;
for(iB0;i<B6;iCC)
41
{
printf(enter the a Ealue for aY?dZ,8i)
scanf(?d,8<);
<CC;
; <B@aY0Z;
for(iB0;i<B6;iCC)
{
printf(Jn?d,8O<);
<CC;
;
.etch( );
;
77.Program to a''ept two "tring" and !igge"t among t#em
#include<stdio.h>
#include<conio.h>
int .etline(char lineYZ8int lim);
main( )
{
char str9Y10Z8str4Y10Z;
int len98len4;
clrscr( );
printf(enter first strin.,);
len9B.etline(str9810);
printf(enter second strin.,);
len4B.etline(str9810);
if(len9 >len4)
printf(first strin. <i..er than second strin.,);
else
if(len9<len4)
printf(second strin. <i..er than first strin.,);
else
printf(<oth strin.s are e[ual,);
.etch( );
;
int .etline(char lineYZ8int lim)
{
int i;
for($i0;i<lim @@ ((lineYiZB.etchar( ))MBSJnS);iCC)
if(lineYiZBBSJnS)
lineYiZBSJ0S;
return i;
;
78.Program to print , dimentiona( matrix wit# 'on"tant nm!er.
#include<stdio.h>
#include<conio.h>
main( )
{
int aY6ZY6Z8i8P8c;
clrscr( );
42
printf(enter constant num<er,);
scanf(?d,8@c); for(iB0;i<6;iC
C)
{ for(PB0;P<6;PC
C) aYiZYPZBc;
for(iB0;i<6;iCC)
{
for(PB0;P<6;PCC)
printf(?d,8aYiZYPZ);
printf(Jn,);
;
.etch( );
;
89.Prongram to a''ept a "tring and print ea'# word in re%er"e
#include<conio.h>
#include<stdio.h>
main( )
{
char nameY10Z;
int i8P8startB08end8len;
clrscr( );
printf(enter a strin.,);
scanf(?s,8name);
for(iB0;i<10 @@((nameYiZB.etchar( ) )MBSJnS);iCC);
lenBi;
for(iB0;i<len;iCC)
if(nameYiZBBS VNN nameYiZBBSJnS)
{
endBi;
Fhile((end33)>Bstart)
{
printf(?c,8nameYendZ);
;
startBiC9;
;
.etch( );
;
81. Program to a''ept e(ement" into "ing(e dimen"iona( arra4 and print t#e arra4 in a"'ending order !4
"ing t#ree di$$erent arra4".
#include<conio.h>
#include<stdio.h>
Eoid read\arraL(int XYZ);
Eoid sort\arraL(int LYZ);
Eoid print\arraL(int UYZ);
main()
{
int aY90Z;
clrscr( );
read\arraL(a);
sort\arraL(a);
43
print\arraL(a);
.etch( );
;
Eoid read\arraL(int XYZ)
{
int i;
for(iB0;i<90;iCC)
{
printf(enter Ealue for aY?dZ,8i);
scanf(?d,8@XYiZ);
;
;
Eoid sort\arraL(int LYZ)
{
int i8P8-;
for(iB0;i<7;iCC)
for(PBiC9;P<B7;PCC)
if(LYiZ>LYPZ)
{ -BLYiZ;
LYiZB
LYPZ;
LYPZB-;
;
;
Eoid print\arraL(int UYZ)
{
int i;
for(iB0;i<90;iCC)
printf(?dJn,8UYiZ);
;
82.Program to a''ept data and "tore t#e gi%en data into $i(e print t#e data.
#include<conio.h>
#include<stdio.h>
main( )
{
>$LE Ofp; char c;
fpBfopen(data.dat,8,F,);
clrscr();
printf(enter teXt,);
Fhile(9)
{
cB.etchar( );
if(cBBeof( ))
<rea-;
putc(c);
;
fclose(fp);
fpBfopen(data.dat,8,r,);
Fhile(9)
{
cB.etc(fp);
if(cBBeof( ))
44
<rea-;
putchar(c);
;
.etch( );
fclose(fp);
;
8&. Program to a''ept data in (ower 'a"e and "tore t#e gi%en data into $i(e into pper 'a"e and print t#e
data.
#include<conio.h>
#include<stdio.h>
main( )
{
>$LE Ofp; har c;
fpBfopen(data4.dat,8,F,);
clrscr( );
printf(enter teXt,);
Fhile((cB.etchar( ))MBeof( ))
{
putc(toupper(c)8fp)
; fclose(fp);
fpBfopen(data4.dat,8,r,);
Fhile(9)
{
cB.etc(fp);
if(cBBeof( ))
<rea-;
putchar(c);
;
.etch( );
fclose(fp);
;
8,.Program to 'op4 'ontent" o$ one $i(e into anot#er.
#include<conio.h>
#include<stdio.h>
main( )
{
>$LE O fp98Ofp4; char ch;
fp9Bfopen(teXt9,8,F,);
printf(enter the teXt,);
Fhile((chB.etchar()MBEO>);
putc(ch8fp9);
fclose(fp9);
fp9Bfopen(teXt9,8,r,);
fp4Bfopen(teXt4,8,F,);
Fhile((chB.etc(fp9))MBEO>)
putc(ch8fp4);
45
fcolse(fp9);
fcolse(fp4);
.etch( );
;
8.. Program to 'reate a $i(e o$ nm!er" and 'op4 odd nm!er into "e'ond $i(e and e%en nm!er into
t#ird $i(e
#include<conio.h>
#include<stdio.h>
main( )
{
>$LE Ofp98Ofp48Ofp:; int i;
fp9Bopen(data9,8F,);
printf(enter the num<er,);
scanf(?d,8@i); Fhile(iM
Beof)
{ putF(i8fp9);
scanf(?d,8@i);
;
fcolse(fp9);
fp9Bfopen(data9,8,r,);
fp4Bfopen(data4,8,F,);
fp:Bfopen(data:,8,F,);
Fhile((iB.etc(fp9))MBeof)
if(i?4BB0)
putc(i8fp:);
else
putF(i8fp4);
fcolse(fp9);
fcolse(fp4);
fcolse(fp:);
.etch( );
;
83.Program to a''ept a "tring in (ower 'a"e and print $ir"t '#ara'ter o$ ea'# word in pper 'a"e.
#include<conio.h>
#include<stdio.h>
main( )
{
char str9Y10Z;
int len.th8i;
clrscr( );
printf(enter a strin.; );
len.thB.etline(str9810);
for(iB0;i<len.th;iCC)
{
str9Y0Z3B:4;
if(str9YiZB BS V)
str9YiC9Z3B:4;
printf(?c,.str9YiZ);
;
46
.etch();
;
int .etline(char line YZ8 int lim)
{
int i;
for(iB0;i<lim @@ ((lineYiZB.etchar( ))MBSJnS);iCC);
if(lineYiZB BSJnS)
lineYiZBSJ0S;
return i;
;
85.Program to a''ept two nm!er" and inter'#ange two %a(e" "ing $n'tion".
#include<conio.h>
#include<stdio.h>
Eoid sFap (int a8 int <);
main( )
{
int a8<;
clrscr( );
printf(enter Ealue for a;,);
scanf(?d,8@a);
printf(enter Ealue for <;,);
scanf(?d,8@<);
sFap(a8<);
.etch( );
;
Eoid sFap(int a8int <)
;
int c;
cBa;
aB<;
<Bc;
printf(JnaB?d,8a);
printf(Jn<B?d,8<);
;
87.Program $or examp(e o$ "tati' %aria!(e.
#include<conio.h>
#include<stdio.h>
static int iB9;
main( )
{
int P;
clrscr( );
for (PB9;P<B5;PCC);
fun( );
.etch( );
;
fun( )
{ printf(Jn
?d,8i); iBiC9;
;
47
88.Program to a''ept a "tring and print !4 trai(ing "pa'e".
#include<conio.h>
#include<stdio.h>
main( )
{
char n8n9;
clrscr ( );
printf(enter a strin.;,);
Fhile((nB.etchar( )MBSJnS)
if(n>BSaS @@ n<BSUS)
putchar(n);
else
if(n>BSaS @@ n<BSUS)
putchar(n);
.etch( );
;
199. Program to print anti diagona(.
#include<conio.h>
#include<stdio.h>
main( )
{
int aY6ZY6Z8i8P8c;
clrscr( );
printf(enter Fhich num<er Lou Fant;,);
scanf(?d,8@c);
for(iB0;i<6;iCC)
for(PB0;P<6;PCC)
if(iCPB B:)
aYiZZPZBc;
else aYiZYPZB0
for(iB0;i<6;iCC)
{ for(PB0;P<6;PCC)
printf(?d,8aYiZYPZ);
printf(Jn,);
;
.etch( );
;
48

You might also like