You are on page 1of 58

SAMPLE PROGRAMS: 1.Write a program to find the area and circumference of the circle.

ALGORITHM: Step-1 Start the program. Step-2 Input the radius of the circle. Step-3 Find the area and circumference of the circle using the formula Area=3.14*r*r ircumference=2*3.14*r Step-4 !rint the area and the circumference of the circle Step-" Stop PROGRAM: #*$% FI&' $() A*)A A&' I* +,F)*)& ) %F $() I* -)*# .include/stdio.h0 main12 3 float rad4area4circum5 printf167n)nter the radius of the circle825 scanf169f84:rad25 area=3.14*rad*rad5 circum=2*3.14*rad5 printf167nArea=9f84area25 printf167n ircumference=9f84circum25 ; SAMPLE INPUT AND OUTPUT: )nter the radius of the circle " Area=<=.">>>>> ircumference=31.4>>>>> 2. Write a program to insert an e ement in an arra! in t"e gi#en position ALGORITHM: Step-1 Start the program Step-2 )nter the si?e of the arra@ Step-3 )nter the elements of the arra@

Step-4 !rint the elements of the arra@ Step-" )nter the element to Ae inserted and its position in the arra@ Step-B Set a loop up to the position @ou enter Step-< !ush the order of the position A@ one4 Chich are greater4 then the position @ou entered Step-= Insert the element in the position entered A@ @ou Step-D !rint the arra@ after insertion of the element Step-1> Stop PROGRAM: #*I&S)*$I&E A& )-),)&$S I&$% $() F) $%**# .include/stdio.h0 main12 3 int aG1>>H4no4i4pos4item5 printf167n)nter the si?e of the matriI825 scanf169d84:no25 printf167n)nter the elements of the matriI825 for1i=>5i/no5iJJ2 scanf169d84:aGiH25 printf167n)ntered elements of the matriI is825 for1i=>5i/no5iJJ2 printf167n9d84aGiH25 printf167n)nter the element and its position in the arra@825 scanf169d7n9d84:item4:pos25 noJJ5 for1i=no5i0=pos5i-2 aGiH=aGi-1H5 aG-posH=item5 printf167n825 printf167nArra@ after the insertion825 for1i=>5i/no5iJJ2 printf167n9d84aGiH25 ; SAMPLE OUTPUT: )nter the si?e of the arra@ " )nter the elements of the arra@ 124"B )ntered elements of the arra@ 124"B )nter the element and its position in the arra@

3 Arra@ after the insertion 1 2 3 4 " B $rite a program to print t"e as%en&ing an& &es%en&ing or&er o' t"e gi#en arra!. ALGORITHM: Step-1 Start the program Step-2 )nter the si?e of the arra@ Step-3 )nter the elements of the arra@ Step-4 Set a loop up to the arra@ si?e minus one Step-" Set a inner loop up to the si?e of the arra@ Step-B hecK Chether the neIt arra@ element is greater than or not Step-< If greater than eIchange their position Step-= If not greater than then go to the loop Step-D After the eIecution of the inner loop the outer loop is eIecuted Step-1> !rint the ascending order of the giLen arra@ Step-11 !rint the descending order of the giLen arra@ Step-12 Stop PROGRAM: #*AS )&'I&E A&' ')S )&'I&E %*')* %F $() EIF)& &+,M)*S*# .include/stdio.h0 main12 3 int numG1>>H4no4i4N4a5 printf16)nter +pper -imit...825 scanf169d84:no25 printf16)nter the numAers825 for1i=>5i/no5iJJ2 scanf169d84:numGiH25 for1i=>5i/no-15iJJ2 3 for1N=iJ15N/no5NJJ2 3 if1numGiH/numGNH2 3 a=numGiH5 numGiH=numGNH5 numGNH=a5 ; ; ; printf167n$he ascending order of the giLen numAers825

for1i=>5i/no5iJJ2 printf167n9d84numGiH25 printf167n $he descending numAer of the giLen numAers825 for1N=no-15N0=>5N-2 printf167n9d84numGNH25 ; SAMPLE OUTPUT )nter the numAer hoC man@ numAer @ou Cant to sort " )nter the numAers 1> 3> "> B> 2> $he ascending order of the giLen numAers 1> 2> 3> "> B> $he descending numAer of the giLen numAers B> "> 3> 2> 1> (.AIM: $o Crite a program to conLert the Ainar@ numAer into decimal numAer ALGORITHM: Step-1 Start the program Step-2 )nter the Ainar@ Lalue Step-3 Set a loop Step-4 onLert the Ainar@ numAer into decimal A@ using statement giLen AeloC Find the digit decimal=decimalJ1digit//Aase25 Aase=AaseJ15 Ainar@ numAer=Ainar@numAer#1>5 Step-" After the eIecution of the loop print the decimal Lalue eOuiLalent to the entered Ainar@ numAer Step-B Stop PROGRAM: ## %&F)*$ MI&A*P &+,M)* I&$% ') I,A- &+,M)* .include/stdio.h0 main12 3 int Anum4digit4decimal=>4Ain4Aase=>5 printf167n)nter the Ainar@ numAer...825 scanf169d84:Anum25 printf169d84Anum25 Ain=Anum5

Chile1AnumQ=>2 3 digit=Anum91>5 decimal=decimalJ1digit//Aase25 Aase=AaseJ15 Anum=Anum#1>5 ; printf167n$he Ainar@ eOuiLalent of 9d in decimal=9d84Ain4decimal25 ; SAMPLE OUTPUT: )nter the Ainar@ numAer...1>> $he Ainar@ eOuiLalent of 1>> in decimal=4 ).AIM: $o Crite a program to find the cosine Lalue of the giLen I ALGORITHM: Step-1 Start the program Step-2 )nter the Lalue of R Step-3 onLert R into radian Step-4 Set a loop Step-" Find the Lalue of cosine using the formula temp=temp*poC11douAle21-1241douAle212*i-122*I*I#12*i*12*i-1225 sum=sumJtemp5 Step-B After the eIecution of the loop print the cosine Lalue Step-< Stop PROGRAM: ## $% FI&' $() %SI&) FA-+) .include/stdio.h0 .include/math.h0 main12 3 float I4a4sum4temp5 int i4no=2>4mul5 printf167n)nter the Lalue of I825 scanf169f84:I25 a=I5 I=I*3.1412#1=>5 temp=15sum=15 for1i=15i/noJ15iJJ2 3

temp=temp*poC11douAle21-1241douAle212*i-122*I*I#12*i*12*i-1225 sum=sumJtemp5 ; printf167n$he cosine Lalue of 9f is 9f84a4sum25 ; SAMPLE OUTPUT )nter the Lalue of I 4" $he cosine Lalue of 4".>>>>>> is >.<><1<B *.AIM: $o Crite a !rogram to find the eIponent of the giLen numAer ALGORITHM: Step-1 Step-2 Step-3 Step-4 Start the program )nter the I Lalue and n Lalue Set a loop up to n Find the eIponent Lalue of I temp=temp*I#i sum=sumJtemp Step-" After the eIecution of the loop print the eIponent Lalue of I Step-B Stop PROGRAM: ##)R!%&)&$IA- S)*I)S .include/stdio.h0 main12 3 float I4temp=14sum=15 int i4no5 printf16)nter the numAers825 scanf169f 9d84:I4:no25 for1i=15i/no5iJJ2 3 temp=temp*I#i5 sum=sumJtemp5 ; printf16)Iponent of I is 9f7n84sum25 ; SAMPLE OUTPUT:

)nter the numAers " " )Iponent of I is B".3<">>> +.AIM: $o Crite a program to find the factorial of the giLen numAer ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" PROGRAM: ##$% FI&' $() FA $%*IA- %F $() EIF)& &+,M)* .include/stdio.h0 main12 3 int fact=14i4num5 printf16)nter the numAer825 scanf169d84:num25 for1i=15i/=num5iJJ2 3 fact=fact*i5 ; printf16$he factorial of 9d is 9d84num4fact25 ; SAMPLE INPUT AND OUTPUT: )nter the numAer " $he factorial of " is 12> ,.AIM: $o Crite a program to conLert the elsius into Fahrenheit ALGORITHM: Step-1 Start the program. Start the program )nter a numAer Set a loop to find the factorial of the giLen numAer using the formula Fact=Fact*I !rint the factorial of the giLen numAer Stop

Step-2 )nter the elsius Lalue. Step-3 alculate the Fahrenheit Lalue A@ using the formula giLen AeloC. Fahreheit=11.=* elsius2J32 Step-4 !rint the Fahrenheit Lalue Step-" Stop PROGRAM: ## %&F)*$ $() )- I+S I&$% FA(*)&$)I)$ .include/stdio.h0 main12 3 float cel4faren5 printf16)nter the elsius Lalue...825 scanf169f84:cel25 faren=11.=*cel2J325 printf16$he fahrenteiet Lalue of the giLen 9f celsius Lalue is 9f84cel4faren25 ; SAMPLE INPUT AND OUTPUT )nter the elsius Lalue...4" $he fahrenteiet Lalue of the giLen 4".>>>>>> celsius Lalue is 113.>>>>>> -.AIM: $o Crite a program to generate the fiAAonaci series ALGORITHM: Step-1 Start the program Step-2 )nter the numAer Step-3 hecK the numAer Chether the numAer is ?ero or not. If ?ero print Sero Lalue. If not ?ero go further. Step-4 Set a loop up to the giLen numAer. Step-" fiA=fiAJa5 a=A5 A=c5 Step-B )Ler@ increment in the loop prints the Lalue of fiA. Step-< After the eIecution of the loop stops the program PROGRAM: ##$% !*I&$ $() FIMM%&A I S)*I)S +!$% EIF)& &+,M)*S .include/stdio.h0

main12 3 int num4fiA=>4a=>4A=14i5 printf16)nter the numAer825 scanf169d84:num25 printf167n FIMM%&A I S)*I)S7n825 if1num==>2 printf16>825 else 3 for1i=>5i/num5iJJ2 3 fiA=fiAJa5 a=A5 A=fiA5 printf169d7t84fiA25 ; ; ; SAMPLE INPUT AND OUTPUT )nter the numAer " FIM%&A I S)*I)S >1123 ./.AIM: $o Crite a program to store the data in a file and read the data from the file. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Step-= Step-D PROGRAM: ##'A$A FI-) .include/stdio.h0 main12 Start the program Initiali?e the file pointer %pen the file in the Crite mode using file pointer )nter the data Store the data in the file using the putc12 statement lose the file %pen the file in the read mode using the file pointer !rint the data in the file )nd

3 FI-) *fp5 char c5 fp=fopen16Write848C825 printf16)nter the teIt....825 Chile11c=getchar122Q=)%F2 putc1c4fp25 fclose1fp25 printf16$he entered data is....825 fp=fopen16Write848r825 Chile11c=getc1fp22Q=)%F2 printf169c84c25 fclose1fp25 ; SAMPLE OUTPUT: )nter the teIt.... Welcome to T U language VS $he entered data is.... Welcome to T U language ...AIM: !rogram to illustrate functions Cithout arguments and no return Lalues. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B PROGRAM: ##F+& $I%&S WI$( %+$ A*E+,)&$S A&' &% *)$+*& FA-+)S .include/stdio.h0 main12 3 Loid message1Loid25 message125 ; Loid message12 3 char strG1>>H5 printf16)nter a string........825 Start the program 'eclare the function all the function )nter the String !rint the string )nd the program in the calling function

scanf169s84str25 printf16W)- %,) $%...9s84str25 ; SAMPLE OUTPUT: )nter a string -AW W)- %,) $% -AW .2.AIM: $o Crite a program to illustrate function Cith arguments and no return Lalue. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B PROGRAM: ##F+& $I%&S WI$( A*E+,)&$S M+$ &% *)$+*& FA-+)S .include/stdio.h0 main12 3 int a4A5 printf16)nter tCo numAers....825 scanf169d9d84:a4:A25 add1a4A25 ; add1int a4int A2 3 int c5 c=aJA5 printf16$he addition of tCo numAers 9d and 9d is 9d84a4A4c25 ; SAMPLE OUTPUT )nter tCo numAers....1> 2> $he addition of tCo numAers 1> and 2> is 3> .0.AIM: !rogram to illustrate parameter passed to the function. Start the program )nter the tCo numAers all the function Cith arguments passing to the calling function Add the tCo numAers in the calling function !rint the addition of tCo Lalues )nd the program in the calling function

ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Step-= Start the program )nter the si?e of the arra@ )nter the elements of the arra@ !rint the arra@ elements all the function Cith Aase address of the arra@ passed to it In the calling function gets the Aase address in the pointer LariaAle Add the arra@ elements *eturn the Lalue from the calling function to the LariaAle in the called function Step-D !rint the sum in the called function Step-1> )nd the program in the main function PROGRAM: ##illustrate parameter passed to the function .include/stdio.h0 main12 3 int aG1>H4i4no4sum=>5 printf16)nter the si?e of arra@...825 scanf169d84:no25 printf16)nter the elements of the arra@...825 for1i=>5i/no5iJJ2 scanf169d84:aGiH25 for1i=>5i/no5iJJ2 printf167n9d84aGiH25 sum=add1:aG>H4no25 printf167n$he sum of 9d numAers is...9d84no4sum25 ; add1int *pt4int n2 3 int i4a=>5 for1i=>5i/n5iJJ2 3 a=aJ*pt5 ptJJ5 ; return1a25 ; SAMPLE OUTPUT: )nter the si?e of arra@... "

)nter the elements of the arra@ ... 1 2 3 4 1 2 3 4 $he sum of " numAers is... 1"

" "

.(.AIM: $o Crite a program to illustrate a function Cith arguments Cith return Lalues. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< PROGRAM: ##F+& $I%& WI$( A*E+,)&$S A&' *)$+*& FA-+)S .include/stdio.h0 main12 3 int a4A4c5 printf16)nter the tCo numAers...825 scanf169d 9d84:a4:A25 c=add1a4A25 printf16$he addition of tCo numAers 9d and 9d is 9d84a4A4c25 ; add1int I4int @2 3 int ?5 ?=IJ@5 return1?25 ; SAMPLE OUTPUT: )nter the tCo numAers... " B $he addition of tCo numAers " and B is 11 .).AIM: $o Crite a program to find the largest and smallest of the giLen arra@. Start the program )nter the tCo numAers all the function Cith tCo arguments passed to it Add the tCo numAers in the calling function *eturn the addition Lalue to the called function from the calling function !rint the addition Lalue in the main function )nd

ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Start the program )nter the si?e of arra@ )nter the elements of the arra@ !rint the arra@ elements Initiali?e the large and small is eOual to the first element of the arra@ Set a loop up to the arra@ si?e hecK the neIt element greater then the larger. If greater then as sign neIt element to the large Step-= hecK the neIt element smaller then the larger. If smaller then assign neIt element to the small Step-D !rint the Lalue of large and small after the eIecution of the loop Step-1> Stop PROGRAM: ##FI&' $() -A*E)S$ A&' S,A--)S$ %F $() EIF)& A**AP .include/stdio.h0 main12 3 int aG1>>H4i4small4large4no5 printf16In hoC man@ numAers @ou Cant to find....825 scanf169d84:no25 printf16)nter the elements of the arra@....825 for1i=>5i/no5iJJ2 scanf169d84:aGiH25 printf167n$he elements of the arra@ 625 for1i=>5i/no5iJJ2 printf167n9d84aGiH25 small=aG>H5 large=aG>H5 for1i=15i/no5iJJ2 3 if1aGiH0large2 large=aGiH5 else if1aGiH/small2 small=aGiH5 ; printf167n$he largest of the giLen arra@ is 9d84large25 printf167n$he smallest of the giLen arra@ is 9d84small25 ; SAMPLE OUTPUT: In hoC man@ numAers @ou Cant to find...."

)nter the elements of the arra@.... 12 34 "B =< 43 $he elements of the arra@ 12 34 "B =< 43 $he largest of the giLen arra@ is =< $he smallest of the giLen arra@ is 12 .*.AIM: $o Crite a program to giLe the addition of tCo matriIes. ALGORITHM: Step-1 Start the program Step-2 )nter the roC and column of the matriI Step-3 )nter the elements of the A matriI Step-4 )nter the elements of the M matriI Step-" !rint the A matriI in the matriI form Step-B !rint the M matriI in the matriI form Step-< Set a loop up to the roC Step-= Set a inner loop up to the column Step-D Add the elements of A and M in column Cise and store the result in matriI Step-1> After the eIecution of the tCo loops. !rint the Lalue of matriI Step-11 Stop PROGRAM: ## FI&' $() A''I$I%& %F $W% ,A$*IR)S .include/stdio.h0 main12 3 int aG2"HG2"H4AG2"HG2"H4cG2"HG2"H4i4N4m4n5 printf16)nter the roCs and column of tCo matriIes...7n825 scanf169d 9d84:m4:n25 printf167n)nter the elements of A matriI...825 for1i=>5i/m5iJJ2 3 for1N=>5N/n5NJJ2 scanf169d84:aGiHGNH25 ; printf167n)nter the elements of M matriI...825 for1i=>5i/m5iJJ2 3 for1N=>5N/n5NJJ2 scanf169d84:AGiHGNH25

; printf167n$he elements of A matriI825 for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 printf167t9d84aGiHGNH25 ; printf167n$he elements of M matriI825 for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 printf167t9d84AGiHGNH25 ; printf167n$he addition of tCo matriIes825 for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 3 cGiHGNH=aGiHGNHJAGiHGNH5 printf167t9d84cGiHGNH25 ; ; ; SAMPLE OUTPUT: )nter the roCs and column of tCo matriIes... 3 3 )nter the elements of A matriI... 1 2 3 4 " B < = D )nter the elements of M matriI... 1 2 3 4 " B < = D $he elements of A matriI 1 2 3 4 " B < = D $he elements of M matriI 1 2 3 4 " B < = D $he addition of tCo matriIes 2 4 B = 1> 12 14 1B 1= .+.AIM:

$o Crite a program to multipl@ tCo matriIes. ALGORITHM: Step-1 Start the program Step-2 )nter the roC and column of the A matriI Step-3 )nter the roC and column of the M matriI Step-4 )nter the elements of the A matriI Step-" )nter the elements of the M matriI Step-B !rint the elements of the A matriI in matriI form Step-< !rint the elements of the M matriI in matriI form Step-= Set a loop up to roC Step-D Set a inner loop up to column Step-1> Set another inner loop up to column Step-11 ,ultipl@ the A and M matriI and store the element in the Step-12 !rint the resultant matriI Step-13 Stop PROGRAM: ## ,+-$!-I A$I%& %F $W% ,A$*IR .include/stdio.h0 main12 3 int aG2"HG2"H4AG2"HG2"H4cG2"HG2"H4i4N4K4r4s5 int m4n5 printf167n)nter the *oCs and olumns of A matriI...825 scanf169d 9d84:m4:n25 printf167n)nter the *oCs and olumns of M matriI...825 scanf169d 9d84:r4:s25 if1mQ=r2 printf167n$he matriI cannot multiplied825 else 3 printf167n)nter the elements of A matriI825 for1i=>5i/m5iJJ2 3 for1N=>5N/n5NJJ2 scanf167t9d84:aGiHGNH25 ; printf167n)nter the elements of M matriI825 for1i=>5i/m5iJJ2 3 for1N=>5N/n5NJJ2 scanf167t9d84:AGiHGNH25 ;

matriI

printf167n$he elements of A matriI825 for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 printf167t9d84aGiHGNH25 ; printf167n $he elements of M matriI825 for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 printf167t9d84AGiHGNH25 ; for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 3 cGiHGNH=>5 for1K=>5K/m5KJJ2 cGiHGNH=cGiHGNHJaGiHGKH*AGKHGNH5 ; ; ; printf16$he multiplication of tCo matriIes825 for1i=>5i/m5iJJ2 3 printf167n825 for1N=>5N/n5NJJ2 printf167t9d84cGiHGNH25 ; ; SAMPLE INPUT AND OUTPUT )nter the *oCs and olumns of A matriI... 3 3 )nter the *oCs and olumns of M matriI... 3 3 )nter the elements of A matriI 1 2 3 4 " B < = D )nter the elements of M matriI 1 2 3 4 " B < = D $he elements of A matriI 1 2 3 4 " B < = D $he elements of M matriI 1 2 3

4 " B < = D $he multiplication of tCo matriIes 3> 3B 42 BB =1 DB 1>2 12B 1"> .,.AIM: $o find sum of 'igits4 *eLerse and the giLen &umAer is !alindrome or not. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Step-= Start the program )nter the numAer Set a loop upto the numAer is not eOual to ?ero Find the digit of the numAer Find the sum of digit Find the reLerse numAer After the end of the loop print the sum and reLerse numAer of the digit Find Chether the reLerse numAer is eOual to the giLen numAer or not. If eOual the numAer is palindrome Step-D If not eOual the giLen numAer is not palindrome Step-1> Stop PROGRAM: #* !*%E*A, $% FI&' $() S+, A&' *)F)*S) %F $() EIF)& &+,M)**# .include/stdio.h0 main12 3 unsigned long int a4num4sum=>4rnum=>4rem5 printf167n)nter the numAer...825 scanf169ld84:num25 a=num5 Chile1numQ=>2 3 rem=num91>5 sum=sumJrem5 rnum=rnum*1>Jrem5 num=num#1>5 ; printf167n$he sum of the digits of 9ld is 9ld7n84a4sum25 printf167n$he reLerse numAer of the 9ld is 9ld84a4rnum25 if1a==rnum2 printf167n$he giLen numAer is a palindrome825 else

printf167n$he giLen numAer is not a palindrome825 ; Samp e o1tp1t: )nter the numAer...12321 $he sum of the digits of 12321 is D $he reLerse numAer of the 12321 is 12321 $he giLen numAer is a palindrom .-.AIM: $o Crite a program to find the roots of the Ouadratic eOuation. ALGORITHM: Step-1 Start the program Step-2 )nter the Lalue of a4 A4 c Step-3 Find the Lalue of d A@ using the formula '=A*A-4*a*c Step-4 If ' is greater then or eOual to ?ero then find the tCo roots as root1=1AJsOrt1d22#12*a25 root2=1-A-sOrt1d22#12*a25 !rint the tCo roots Step-" If the ' is not greater then or eOual to ?ero then print the statement the roots are imaginar@. Step-B Stop PROGRAM: ## $o find the roots of the Ouadratic eOuation .include/stdio.h0 .include/math.h0 main12 3 int a4A4c4d5 float root14root25 printf16)nter the Lalues of a4A4c7n825 scanf169d 9d 9d84:a4:A4:c25 d=A*A-4*a*c5 if1d0=>2 3 root1=1-AJsOrt1d22#12*a25 root2=1JAJsOrt1d22#12*a25 printf16$he roots of the Lalues a=9d4A=9d4c=9d are7n 9f 9f84a4A4c4root14 root225 ;

else printf16$he roots are imagenar@825 ; SAMPLE OUTPUT: )nter the Lalues of a4A4c 1 > -D $he roots of the Lalues a=14A=>4c=-D are 3.>>>>>> 3.>>>>>> 2/.AIM: $o Crite a program to find the factorial of the giLen numAer using recursion ALGORITHM: Step-1 Start the program Step-2 )nter the numAer Step-3 all the recursiLe function passing the numAer to the recursiLe function as an argument. Step-4 If the entered numAer is eOual to one then return one to main function. Step-" If the numAer is less greater then one then call recursiLe Step-B !rint the factorial Lalue of the numAer. Step-< Stop PROGRAM: .include/stdio.h0 main12 3 int num4a5 printf16)nter the numAer825 scanf169d84:num25 a=recur1num25 printf16$he factorial of the numAer 9d is 9d84num4a25 ; recur1int no2 3 int fact=15 if1no==12 return1125 else fact=no*recur1no-125 ; SAMPLE OUTPUT: )nter the numAer "

$he factorial of the numAer " is 12> 2..AIM: $o Crite a program to find Chether the string is palindrome or not. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Start the program )nter the string Find the string length using the strlen12 function !rint the string length Set a loop up to the half of the string length ompare eLer@ character aAoLe the middle character Cith the AeloC character of the middle character Step-< If an@ character eOual prints the giLen string is palindrome Step-= If the character is not eOual then print the giLen string is not a palindrome Step-D Stop PROGRAM: ##$% FI&' W()$()* $() EIF)& S$*I&E IS !A-I&'*%,) %* &%$ .include/stdio.h0 .include/stdliA.h0 main12 3 int len=>4i4N5 char nameG2"H5 printf16)nter the string...825 scanf169s84name25 Chile1nameGlenHQ=U7>X2 lenJJ5 printf167n9d84len25 for1i=>4N=len-15i/len#25iJJ4N-2 3 if1nameGiHQ=nameGNH2 3 printf167n$he giLen string is not a palindrom825 eIit1>25 ; ; 22. AIM: $o find the numAer of LoCels and numAer of consonants in a giLen string. PROGRAM:

##$% FI&' $() &+,M)* F%W-)S A&' &+,M)* %F %&S%&A&$S I& A EIF)& S$*I&E .include/stdio.h0 main12 3 int L=>4c=>4i=>5 char strG2"H5 printf16)nter the string...825 scanf169s84str25 Chile1strGiHQ=U7>X2 3 sCitch1strGiH2 3 case TaUY case TAUY case T)UY case TIUY case T%UY case T+UY case TeUY case TiUY case ToUY case TuUY LJJ5 AreaK5 defaultY cJJ5 ; iJJ5 ; printf167n$he numAer of LoCels is 9d84L25 printf167n$he numAer of consonants is 9d84c25 getch125 ; SAMPLE OUTPUT: )nter the string *AZA $he numAer of LoCels is 2 $he numAer of consonants is 2 20.AIM: $o Crite the program to transpose the giLen matriI. ALGORITHM:

Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Step-= PROGRAM:

Start the program )nter the roC and column of the matriI )nter the elements of the matriI !rint the elements of the matriI in the matriI format Set the loop up to roC Set the inner loop up to column !rint the matriI elements in the roC Cise Stop

##$*A&S!%S) %F EIF)& ,A$*IR .include/stdio.h0 main12 3 int i4N4aG2"HG2"H4roC4col5 printf167n)nter the numAer of roCs and column of matriI825 scanf169d9d84:roC4:col25 printf167n)nter the elements of the matriI825 for1i=>5i/roC5iJJ2 for1N=>5N/col5NJJ2 scanf169d84:aGiHGNH25 printf16$he giLen matriI825 for1i=>5i/roC5iJJ2 3 printf167n825 for1N=>5N/col5NJJ2 printf167t9d84aGiHGNH25 ; printf167n$he transpose of the giLen matriI825 for1i=>5i/roC5iJJ2 3 printf167n825 for1N=>5N/col5NJJ2 printf167t9d84aGNHGiH25 ; ; SAMPLE OUTPUT: )nter the numAer of roCs and column of matriI 3 3 )nter the elements of the matriI 1 2 3 4 " B < = D $he giLen matriI 1 2 3 4 " B

< = D $he transpose of the giLen matriI 1 4 < 2 " = 3 B D 2(.AIM: $o Crite a program to find the sine Lalue for the entered Lalue. ALGORITHM Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< PROGRAM: ## SI&) S)*I)S .include/stdio.h0 .include/math.h0 main12 3 int no4i5 float I4a4sum4A5 printf16)nter the numAers825 scanf169f 9d84:I4:no25 A=I5 I=I*3.141#1=>5 a=I5 sum=I5 for1i=15i/noJ15iJJ2 3 a=1a*poC11douAle21-1241douAle212*i-122*I*I2#12*i*12*iJ1225 sum=sumJa5 ; printf16Sin19f2 Lalue is 9f84A4sum25 ; SAMPLE OUTPUT: )nter the numAers 3> Start the program )nter the Lalues I and n onLert the Lalue I into radians Set a loop up to n Find the Lalue of the sine A@ using the formula !rint the Lalue of sine I after the eIecution of the loop stop

1>> Sin13>.>>>>>>2 Lalue is >.4DDD14 2).AIM: $o Crite a program to print the student name4 roll no4 aLerage marK and their grades. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Step-D PROGRAM: ##S$+')&$ *) %*' +SI&E !%I&$)* A&' S$*+ $ .include/stdio.h0 main12 3 struct student 3 char nameG2"H5 char regnoG2"H5 int aLg5 char grade5 ; studG">H4*pt5 int i4no5 printf16)nter the numAer of the students...825 scanf169d84:no25 for1i=>5i/no5iJJ2 3 printf167n studentG9dH informationY7n84iJ125 printf16)nter the name825 scanf169s84studGiH.name25 printf167n)nter the roll no of the student825 scanf169s84studGiH.regno25 printf167n)nter the aLerage Lalue of the student825 scanf169d84:studGiH.aLg25 ; pt=stud5 for1pt=stud5pt/studJno5ptJJ2 3 Start the program Initiali?e the structure LariaAle )nter the numAer of student Set a loop up to the numAer of student )nter the student name4 roll no4 aLerage marKs Find their grades !rint the student name4 roll no4 aLerage and their grade Stop

if1pt-0aLg/3>2 pt-0grade=U'U5 else if1pt-0aLg/">2 pt-0grade=U U5 else if1pt-0aLg/<>2 pt-0grade=UMU5 else pt-0grade=UAU5 ; printf167n825 printf16&A,) *)EIS$)*-&% AF)*AE) E*A')7n825 for1pt=stud5pt/studJno5ptJJ2 3 printf169-2>s9-1>s84pt-0name4pt-0regno25 printf1691>d 7t 9c7n84pt-0aLg4pt-0grade25 ; ; SAMPLE OUTPUT: )nter the numAer of the students 3 studentG1H informationY )nter the name ,+&I )nter the roll no of the student 1>> )nter the aLerage Lalue of the student D" studentG2H informationY )nter the name -AW )nter the roll no of the student 2>> )nter the aLerage Lalue of the student "" studentG3H informationY )nter the name *AZA )nter the roll no of the student 3>> )nter the aLerage Lalue of the student 2" &A,)*)EIS$)*-&% AF)*AE) ,+&I 1>> D" A -WA 2>> "" M *AZA 3>> 2" '

E*A')

2*.AIM: $o Crite a program to sCap tCo numAer Cithout using pointer ALGORITHM: Step-1 Start the program Step-2 )nter the tCo numAers

Step-3 Step-4 Step-" Step-B Step-< Step-= PROGRAM:

all the displa@ function !ass the address of the tCo numAers to the calling function Eet the address in the calling function in the pointer SCap the numAer using temporar@ LariaAle !rint the sCamped Lalues in the main function Stop

## SWA! $() &+,M)* +SI&E $() !%I&$)* .include/stdio.h0 main12 3 int I4@5 printf167n)nter the tCo numAers825 scanf16 9d 9d84:I4:@25 printf167n$he entered numAer for I and @ are4I=9d7t@=9d84I4@25 displa@1:I4:@25 printf167nAfter the sCapping the Lalue of4I=9d7t@=9d84I4@25 ; displa@1int *a4int *A2 3 int t5 t=*a5 *a=*A5 *A=t5 ; SAMPLE OUTPUT: )nter the tCo numAers...1> 2> $he entered numAer for I and @ are4 I=1> @=2> After the sCapping the Lalue of4 I=2> @=1> 2+.AIM: $o Crite a program to find the string length and concatenation of string. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Start the program )nter the string Find the string length using the function strlen12 !rint the string length of the entered string concatenation the tCo string using the function strcat12 !rint the concatenated string Stop

PROGRAM: ## $% FI&' $() S$*I&E -)&E$( %F $() S$*I&E .include/stdio.h0 .include/string.h0 main12 3 char str1G">H4str2GH=8 W)- %,)85 int len5 printf16)nter the string...825 scanf169s84str125 printf167n$he string length of 9s is 9d84str14strlen1str1225 printf167n$heconcatenation string length is 9d and its string is 9s84strlen1str124strcat1str14str2225 ; SAMPLE OUTPUT: )nter the string... -AW $he string length of laK is 3 $he concatenation string length is 1B and its string is -AW W)- %,) W 2,.AIM: $o Crite a program to print the pascal triangle ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< PROGRAM: ## %&S$*+ $ !AS A- $*IA&E-) .include/stdio.h0 main12 3 int noline4i4N4temp5 printf16)nter the numAer of lines to print825 scanf169d84:noline25 for1i=15i/=noline5iJJ2 Start the program )nter the numAer of lines onstruct a loop up to the giLen numAer onstruct another inner loop !irnt the numAer After the eIecution of the loop Stop

3 for1N=15N/=noline-i5NJJ2 printf16 625 temp=i5 for1N=15N/=i5NJJ2 printf1694d84tempJJ25 temp=temp-25 for1N=15N/i5NJJ2 printf1694d84temp-25 printf167n7n825 ; printf167n825 ; SAMPLE OUTPUT: )nter the numAer of lines to print " 1 232 34"43 4"B<B"4 "B<=D=<B" 2-.AIM: $o Crite a program to find Chether the numAer is prime %r not. ALGORITHM: Step-1 Start the program Step-2 )nter the numAer Step-3 set a loop up to numAer-1 Step-4 hecK the numAer is diLide A@ an@ numAer other than one and the numAer itself Step-" If diLide aAsolutel@ than print the numAer is not a prime Step-B If not diLide other then one and itself then print the numAer is prime. Step-< Stop PROGRAM: ##FI&' $() EIF)& &+,M)* IS !*I,) %* &%$ .include /stdio.h0 main12 3 int num4i=25 printf16)nter the numAer...825 scanf169d84:num25

Chile1i/=num-12 3 if1num9i==>2 3 printf16$he giLen numAer is not a prime numAer825 AreaK5 ; iJJ5 ; if1i==num2 printf16$he giLen numAer is a prime825 ; SAMPLE OUTPUT: )nter the numAer..." $he giLen numAer is a prime 0/.AIM: $o Crite a program to find the reLerse of the string. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< Start the program )nter the string length !rint the string length )nter the string character A@ character !ass the length of the string to the recursiLe function If the sting length is 1 then print the character If the string length is greater than one then reduces the string length A@ one and call the recursiLe function. Step-= Stop PROGRAM: ##*)F)*S) $() S$*I&E +SI&E $() *) +*SI%& .include/stdio.h0 main12 3 int len5 Loid reL125 printf16)nter the string length825 scanf169d84:len25 printf167n9d84len25 printf167n825 reL1len25

printf167n825 ; Loid reL1len2 int len5 3 char c5 if1len==12 3 c=getchar125 c=getchar125 putchar1c25 ; else 3 c=getchar125 c=getchar125 reL1-len25 putchar1c25 ; return5 ; SAMPLE OUTPUT: )nter the string length 4 4 A,A* *A,A 0..AIM: $o Crite a program to find the si?e of the data t@pes. ALGORITHM: Step-1 Step-2 Step-3 Step-4 PROGRAM: ##$% FI&' $() SIS) %F 'A$AS .include/stdio.h0 main12 3 int i=1>5 Start the program Initiali?e the data t@pes !rint the si?e of the data t@pes using the statement si?eof12 Stop

float f=2".>>"5 char nameGH=8Celcome85 printf167n $he si?e of integer is 9d84si?eof1i225 printf167n $he si?e of float is 9d84si?eof1f225 printf167n $he si?e of character is 9d84si?eof1name225 ;

SAMPLE OUTPUT: $he si?e of integer is...2 $he si?e of float is... 4 $he si?e of character is...= 02.AIM: $o find the sum and aLerage of the giLen arra@ ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Step-B Step-< PROGRAM: ##FI&' $() S+, A&' AF)*AE) %F $() EIF)& &+,M)*S .include/stdio.h0 main12 3 int aG1>>H4i4no4sum=>5 float aLg=>5 printf167n)nter the numAer of elements825 scanf169d84:no25 printf16)nter the numAers825 for1i=>5i/no5iJJ2 3 scanf169d84:aGiH25 sum=sumJaGiH5 ; aLg=1float2sum#no5 printf16sum=9d7naLerage=9f84sum4aLg25 Start the program )nter the si?e of the arra@ )nter the elements of the arra@ Set a loop up to the si?e of the arra@ Find the sum of the arra@ After the eIecution of the loop. !rint the sum and aLerage of the arra@ Stop

; Samp e O1tp1t: )nter the numAer of elements" )nter the numAers 1 2 3 4 " sum=1" aLerage=3.>>>>>> 00.AIM: $o Crite a program to conLert the string into upper case ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" PROGRAM: ## %&F)*$ $() -%W)* AS) $% +!!)* AS) -)$$)* .include/stdio.h0 main12 3 int i=>5 char strG1>>H5 printf16)nter the string825 scanf169s84str25 Chile1strGiHQ=U7>X2 3 printf169c84toupper1strGiH225 iJJ5 ; ; Samp e O1p1t )nter the string Eu*u E+*+ 0(.AIM: $o Crite a program to find the largest of the three numAers. Start the program )nter the string Set a loop up to the null character !rint the character of the string in the upper case using toupper12 function After the eIecution of the loop end the program

ALGORITHM: Step-1 Start the program Step-2 )nter the three numAers Step-3 Assign large to first numAer step-4 hecK the neIt numAer is greater then the large. then assign large to neIt numAer Step-" ompare the neIt numAer Cith large Step-B 'o the step-4 Step-< !rint the larger Lalue of the three numAer Step-= Stop PROGRAM: ##$% FI&' $() -A*E)S$ %F $() $(*)) &+,M)*S .include/stdio.h0 main12 3 int a4A4c4Aig5 printf16)nter the three numAers825 scanf169d 9d 9d84:a4:A4:c25 Aig=a5 if1Aig/A2 Aig=A5 else if 1Aig/c2 Aig=c5 printf16$he Aiggest of three numAer is 9d84Aig25 ; SAMPLE OUTPUT: )nter the three numAers D3 43 23 $he Aiggest of three numAer is D3 0).AIM: $o Crite a program to find the standard deLiation of the giLen arra@. ALGORITHM: Step-1 Step-2 Step-3 Step-4 Step-" Start the program )nter the arra@ si?e )nter the elements of the arra@ !rint the )ntered elements all the function to calculate standard deLiation

If greater

Step-B PROGRAM:

all the aLerage function from the standard deLiation function

## %,!+$) S$A&'A*' ')FIA$I%& +SI&E F+& $I%& .include/stdio.h0 .include/math.h0 main12 3 int i4num5 float deL4listG1>>H5 float standeL125 printf167n)nter the si?e of the list825 scanf169d84:num25 printf167n)nter the elements of the list825 for1i=>5i/num5iJJ2 scanf169f84:listGiH25 printf167n)ntered elements are825 for1i=>5i/num5iJJ2 printf167n9f84listGiH25 deL=standeL1list4num25 printf167n Standard 'eLiatiion of the list is 91>."f7n84deL25 ; float standeL1float lisG1>>H4int no2 3 int i5 float mean4deL4sum=>.>5 float aLg125 mean=aLg1lis4no25 printf167n ,ean of 93d elements is91>.2f7n84no4mean25 for1i=>5i/no5iJJ2 sum=sumJ1mean-lisGiH2*1mean-lisGiH25 deL=sOrt1sum#1float2no25 return1deL25 ; float aLg1float lG1>>H4int n2 3 int i5 float sum=>.>5 for1i=>5i/n5iJJ2 sum=sumJlGiH5 return1sum#1float2n25 ; Samp e O1tp1t

)nter the si?e of the list " )nter the elements of the list 1 2 3 4 " )ntered elements are 1.>>>>>> 2.>>>>>> 3.>>>>>> 4.>>>>>> ".>>>>>> ,ean of " elements is 3.>> Standard 'eLiatiion of the list is 1.41421 0*.AIM: $o Crite a menu driLen program to find 1. Factorial of the giLen numAer 2. !rime numAer or not 3. )Len numAer or %dd numAer 4. )Iit ALGORITHM: Step-1 Start the program Step-2 )nter the numAer Step-3 )nter @our choice using sCitch statement Step-4 If @ou choose the choice 1. Find the factorial Step-" set a loop up to the entered numAer Step-B alculate factorial fact=fact*I Step-< !rint the factorial Lalue Step-= If @ou choose the choice 2.Find Chether the numAer is prime or not Step-D set a loop up to numAer-1 Step-1> hecK the numAer is diLide A@ an@ numAer other than one and the numAer itself Step-11 If diLide aAsolutel@ then print the numAer is not a prime Step-12 If not diLide other than one and itself then print the numAer is prime Step-13 If @ou choose the choice 3. Find Chether the numAer is odd or eLen Step-14 If the numAer is diLide A@ 2 then print the numAer is eLen Step-1" If the numAer is not diLiding A@ 2 then print the numAer is odd Step-1B If @ou choose the choice 4.)Iit the program Step-1< ontinue the program PROGRAM: ## ,)&+ '*IF)& !*%E*A, .include/stdio.h0 main12 3

int num4o4fact=14i5 Chile112 3 printf167n)nter the numAer 625 scanf169d84:num25 printf167nchoose one of the options giLen AeloC825 printf167n1.Factorial of the giLen numAer7n2.!rime numAer or not7n3.%dd or )Len 7n4.)Iit825 scanf169d84:o25 sCitch1o2 3 case 1Y for1i=15i/=num5iJJ2 fact=fact*i5 printf16$he factorial of 9d is 9d84num4fact25 AreaK5 case 3Y if1num92==>2 printf16$he giLen numAer is )Len numAer825 else printf16$he giLen numAer is %dd numAer825 AreaK5 case 2Y i=25 Chile1i/=num-12 3 if1num9i==>2 3 printf16$he giLen numAer is not a prime numAer825 AreaK5 ; iJJ5 ; if1i==num2 printf16$he giLen numAer is a prime825 AreaK5 defaultY eIit1>25 ; ; ; SAMPLE OUTPUT: )nter the numAer .. " hoose one of the options giLen AeloC

1. Factorial of the giLen numAer 2. !rime numAer or not 3. %dd or )Len 4. )Iit 1 $he factorial of " is 12> )nter the numAer.." hoose one of the options giLen AeloC 1.Factorial of the giLen numAer 2.!rime numAer or not 3.%dd or )Len 4.)Iit 2 $he giLen numAer is a prime )nter the numAer..." hoose one of the options giLen AeloC 1.Factorial of the giLen numAer 2.!rime numAer or not 3.%dd or )Len 4.)Iit 4 0+. AIM : $o print ,agic Suare numAers. A gorit"m Step-1 Start the program Step-2 'eclare I4 @ and ? LariaAles as TintU data t@pe. Step-3 for i=1 to less than 1>4 I = IJ 1 Step-3.1 for @Y=? to less than or eOual to 1>4 @ =@J? Step-3.1.1 for ? = 1> to less than or eOual to 1>>4 ?=?J1> print the 6,agic SOuare8 print 6I-?4 IJ?-@4 IJ@8 print 6IJ@J?4 I4 I-@-?8 print 6I-@4 IJ@-?4 IJ?8 Step-4 Stop the program PROGRAM .include /stdio.h0 .include/string.h0 main 1 2 3 int I4 @4 ?5 for 1I=>5 I/=15 IJ=22

for 1@=>5 @/=15 @J=22 for 1?=D5 ?/=1>5 ?J=1>2 3 printf 1[7n7n ,agic SOuare 9d7n7n[4 3JI25 printf 1[9d7t9d7t9d7n[4I-?4IJ?-@4IJ@25 printf 1[9d7t9d7t9d7n[4IJ@J?4I4I-@-?25 printf 1[9d7t9d7t9d7n[4I-@4IJ@-?4IJ?25 getch125 ; ; Samp e o1tp1t ,agic SOuare -D D 3 13 1 -11 -1 -< 11 0,.AIM: !rogram to print $riangle of &umAers. ALGORITHM Step-1 Start the program Step-2 'eclare the LariaAles i4 N4 K4 l and n as 6int8 data t@pe Step-3 *ead & numAers of lines in a triangle Step-4 Initiali?e l=1 Step-" for i=14 N=n-i to less than or eOual to n Step-".1 for K=1 to less than or eOual to N print [ [ Step-".1.1 for K=1 to less than or eOual to T1U print [i[ Step-".2 l is incremented A@ 2 Step-B Stop the program. PROGRAM .include/stdio.h0 main1 2 3 int i4 N4 K4 l4 n5 printf1[$@pe &-no of lines in triangle 7n[2 5 scanf1[9d[4:n25 l=15 for 1i=14 N=n-i5 i/=n5 iJJ4 N--2 3 for 1K=15 K/=N5 KJJ2

printf1[ [25 for 1K=15 K/=l5 KJJ2 printf1[ 9d[4 i25 printf1[7n[2 5 lJ=25 ; ; SAMPLE OUTPUT $@pe &-no of lines in triangle 3 1 2 2 2 3 3 3 3 3 0-.AIM: !rogram to find Chether a @ear is -eap @ear. ALGORITHM Step-1 Start the program Step-2 'eclare @ear as int datat@pe Step-3 *ead the @ear Step-4 hecK if 1@e:1>>2 = > Step-4.1 @e=#1>>5 Step-" hecK if 1@e942 = > Step-".1 !rint 6It is a leap @ear8 Step-B else Step-B.1 print 6It is not a leap @ear8 PROGRAM .include/stdio.h0 main12 3 int @e5 printf 1[)nter the @ear 7n[25 scanf1[9d[4 :@e25 if 1@e94==>2 printf1[It is a -eap Pear 7n[25 else printf1[It is &ot a -eap Pear7n[25 ; SAMPLE OUTPUT

)nter the @ear 2>>> It is a -eap Pear (/. AIM: !rogram to print the folloCing $riangle. " 4 " 3 4 " 2 3 4 " 1 2 3 4 " ALGORITHM Step-1 Start the program Step-2 'eclare i4 N and n as 6int8 data t@pe Step-3 *ead the numAer of lines Step-4 for i=n to greater than or eOual to T>U Step-4.1 for N=i to less than n print 6@8 Step-" Stop the program PROGRAM .include/stdio.h0 main12 3 int i4 N4 n5 printf1[)nter numAer of lines7n[25 scanf1[9d[4 :n25 printf1[7n7n7n[25 for 1i=15i/=n5iJJ2 3 for 1N=15N/=i5NJJ2 printf1[9-2d[4N25 printf1[7n7n[25 ; ; SAMPLE OUTPUT )nter numAer of lines " 1 12 123 1234 1234"

(..AIM: Write a program to read TnU numAers and find the maIimum and the minimum. ALGORITHM Step-1 Start the program Step-2 'eclare arra@ taAleG">H4 i4 cnt4 maI and min as 6int8 data t@pe Step-3 )nter the numAer of elements in the arra@ Step-4 )nter the elements into the arra@ Step-" for i=1 to less than or eOual to TcntU Step-".1 *ead the Lalues from the console. Step-B Initiali?e maI = min = taAle G1H Step-< for i=2 to less than or eOual to TcntU Step-<.1 checK if 1maI / taAle GiH2 Step-<.1.1 maI = taAle GiH Step-<.2.1 min = taAleGiH Step-= print maIimum Lalue and minimum Lalue Step-D Stop the program PROGRAM .include/stdio.h0 main 12 3 int taAleG">H4 i4 cnt4 maI4 min5 clrscr125 printf 1[)nter numAer of elements in the arra@7n[25 scanf1[9d[4 :cnt25 printf1[)nter the elements7n[25 for 1i=15 i/=cnt5 iJJ2 scanf1[9d[4 :taAleGiH25 maI = min = taAleG1H5 for 1i=25 i/=cnt5 iJJ2 3 if 1maI/taAleGiH2 maI = taAle GiH5 else if 1min0taAleGiH2 min = taAleGiH5 ; printf 1[,aIimum Lalue = 9d7n[4maI25 printf 1[,inimum Lalue = 9d[4min25 ; SAMPLE OUTPUT

)nter numAer of elements in the arra@ " )nter the elements 1 4 2 3 " ,aIimum Lalue = " ,inimum Lalue = 1 (2.AIM: !rogram to find the determine of 2 \ 2 matriI. ALGORITHM Step-1 Start the program Step-2 'eclare a tCo-dimensional arra@ aG2HG2H4d4 i and N as 6int8 data t@pe. Step-3 )nter an@ 2\2 matriI Step-4 for i=> to less than 2 Step-4.1 for N=> to less than 2 Step-4.1.1 *ead aGiHGNH Step-" Initiali?e d = aG>HG>H * aG1HG1H - aG>HG1H * aG1HG>HY Step-B print 6'eterminant of matriI8 Step-< for i=> to less than 2 Step-<.1.1 print aGiHGNH Step-= print 6$he 'eterminant Lalue is8 Step-=.1 print 6d8. Step-D Stop the program PROGRAM .include/stdio.h0 main12 3 int aG2HG2H4 d4 i4 N5 printf 1[)nter an@ 2I2 matriI7n[25 for 1i=>5i/25iJJ2 for 1N=>5N/25NJJ2 scanf 1[9d[4 :aGiHGNH25 d=aG>HG>H * aG1HG1H - aG>HG1H * aG1HG>H5 printf 1[--------------------------7n[25 printf1[ ,atriI 7n[2 5 printf 1[--------------------------7n[25 for 1i=>5i/25iJJ2 3 for 1N=>5N/25NJJ2 printf1[9-4d[4 aGiHGNH25 printf1[7n[25 ;

printf 1[--------------------------7n[25 printf 1[7n $he 'eterminant Lalue is 9-4d7n[4d25 ;

SAMPLE OUTPUT )nter an@ 2I2 matriI 1 2 3 4 ---------------,atriI ---------------1 2 3 4 ---------------$he 'eterminant Lalue is -2 (0. AIM: !rogram to checK Chether a matriI is an upper triangular.

ALGORITHM Step-1 Start the program Step-2 'eclare a tCo dimensional arra@ aG1>HG1>H4 i4 N4 m4 n and flag=1 as TintU data t@pe. Step-3 )nter the order of matriI Step-4 )nter the matriI roCCise Step-" for i=> to less than or eOual to TmU Step-".1 for N=> to less than or eOual to TnU Step-".1.1 *ead a GiHGNH Step-B for i=> to less than or eOual to TmU Step-B.1 for N=> to less than or eOual to TnU Step-B.1.1 checK if 1aGiHGNHQ=>2 !rint 6$he giLen matriI is not an upper triangular8 Step-B.1.2 Initiali?e flag=> Step-< hecK if 1flag2 Step-<.1 print 6$he giLen matriI is an upper triangular8 Step-= Stop the program. PROGRAM .include/stdio.h0 main12

3 int i4N4aG1>HG1>H4m4n4flag=15 printf1[)nter the order of the matriI 1m4n2.....[25 scanf1[9d9d[4 :m4 :n25 printf1[7n)nter the matriI roC Cise.....[25 for 1i=>5 i/m5 iJJ2 for 1N=>5 N/n5 NJJ2 scanf1[9d[4 :aGiHGNH25 for 1i=>5 i/m5 iJJ2 for 1N=>5 N/n5 NJJ2 3 if 1aGiHGNHQ= >2 printf1[7n7n $he giLen matriI is not an upper triangular[25 flag = >5 AreaK5 ; if 1flag2 printf1[7n7n $he giLen matriI is an upper triangular[25 ; SAMPLE OUTPUT )nter the order of the matriI 1m4n2.....3 3 )nter the matriI roC Cise..... 123 4"B <=D $he giLen matriI is not an upper triangular ((. AIM: !rogram to demonistrate ,acros Cith arguments. ALGORITHM Step-1 Start the program Step-2 'efine sOuare1I2 as 11I2*1I22 Step-3 'efine for-loop loop 1indeI4 maI2 as for 1indeI=>5 indeI/maI5 indeIJi2 Step-4 'efine maIimum of tCo maI1I4@2 as 11I2 1@22 ] 1I2Y1@22 Step-" 'eclare tCo arra@s LecG1>H4 sOG1>H4 a4 A4 i4 n and large 6int8 data t@pe Step-B print 6!rogram to compute8 print 61. -argest element in the Arra@8 print 62. SOuare of each arra@ element8 Step-< *ead 6Si?e of the Arra@8 Step-= )nter elements of the Arra@

as

Step-D ,acro calling loop 1i4 n2 Step-D.1 *ead the elements and stored in the arra@ Lec1i2 Step-1> $o displa@ arra@ elements A@ calling macro loop 1i4 n2 Step-1>.1 print the 6Lec1i28 Step-11 Initiali?e large=> Step-12 all macro loop 1i4 n2 Step-12.1 ompute SOGiH=SOuare 1LecGiH2 -arge=maI 1large4 Lec1i22 Step-13 print 6-argest arra@ element8 Step-14 print )lement and its SOuare Step-1" Stop the program. PROGRAM .include/stdio.h0 .define sOuare1I2 11I2*1I22 .define loop1indeI4 maI2 for1indeI=>5 indeI / maI5 indeIJJ2 .define maI1I4 @2 111I201@22] 1I2Y1@22 main12 3 int a4 A4 i=>4 n4 large4 LecG1>H4 sOG1>H5 printf1[!rogram to compute Y 7n[25 printf1[1. largest element in the arra@.7n[25 printf1[2. sOuare of each arra@ element.7n7n[25 printf1[)nter Si?e of the arra@..... [25 scanf1[9d[4 :n25 printf1[7n)nter 9d elements of the arra@7n[4 n25 loop1i4n2 scanf 1[9d[4 :LecGiH25 loop1i4 n2 printf1[9"d[4 LecGiH25 large =>5 loop1i4n2 3 sOGiH = sOuare1LecGiH25 large = maI1large4 LecGiH25 ; printf1[7n7n-argest arra@ element is Y 9"d[4 large25 printf1[7n)lement SOuare 7n[25 printf 1[----------------- 7n[25 loop1i4n2 printf1[9"d 9=d7n[4 LecGiH4 sOGiH25 ;

SAMPLE OUTPUT !rogram to compute Y 1. largest element in the arra@. 2. sOuare of each arra@ element. )nter Si?e of the arra@..... " )nter " elements of the arra@ 1 2 3 4 " 1 2 3 4 " -argest arra@ element is Y " )lement SOuare ------------------------1 1 2 4 3 D 4 1B " 2" (). AIM: !rogram to delete duplicates in a Fector

ALGORITHM Step-1 Start the program Step-2 'eclare the LariaAles i4 N4 K4 n4 num and flag=> and declare arra@ a1">2 as TFloatU data t@pe. Step-3 )nter the si?e of Lector Step-4 Initiali?e num=n Step-" )nter Lector elements Step-".1 for i=> to less than TnU *ead aGiH Step-B !rint Lector elements Step-B.1 for i=> to less than TnU print aGiH Step-< *emoLing duplicates Step-<.1 for i=> to less than Tn-1U Step-<.1.1 for N = iJ1 to less than TnU Step-<.1.1 hecK if 1aGiH=aGNH2 n=n-1 Step-<.1.1 flag = 1 Step-<.1.1 N = N-1 Step-= hecK if 1flag==>2 !rint 6&o duplicates found in Lector8 Step-D )lse !rint 6Fector has no. of duplicates and print it8 Step-1> !rint 6Fector after deleting duplicates8 Step-1>.1 for i=> to less than n print8aGiH Step-11 Stop the program.

PROGRAM .include/stdio.h0 main12 3 int i4N4K4n4 num4 flag=>5 float aG">H5 printf1[Si?e of Lector][25 scanf1[9d[4 :n25 num = n5 printf1[7n)nter Fector elements ]7n[25 for 1i=>5 i/n5 iJJ2 scanf1[9f[4 :aGiH25 for 1i=>5 i/n-15 iJJ2 for 1N=iJ15 N/n5 NJJ2 3 if 1aGiH==aGNH2 3 n=n-15 for 1K = N5 K / n5 KJJ2 aGKH = aGKJ1H5 flag = 15 N--5 ; ; if 1flag==>2 printf1[7n&o duplicates found in Lector 7n[25 else 3 if11num-n2==12 3 printf1[7nFector has onl@ one duplicate7n[25 printf1[Fector after deleting duplicates Y 7n[25 for 1i=>5i/n5iJJ2 printf1[9B.2f[4 aGiH25 ; else 3 printf1[7nFector has 9d duplicates 7n7n[4 num-n25 printf1[Fector after deleting duplicates Y 7n[25 for 1i=>5i/n5iJJ2 printf1[9B.2f[4 aGiH25 ; ; ;

SAMPLE OUTPUT Si?e of Lector] " )nter Fector elements ] 1 2 3 2 2 Fector has 2 duplicates Fector after deleting duplicates Y 1.>> 2.>> 3.>> (*. AIM: !rogram to insert an element into the Fector

ALGORITHM Step-1 Start the program Step-2 'eclare the LariaAles i4 N4 K4 n and pos as 6int8 and item as TfloatU data t@pe. Step-3 )nter the si?e of Lector Step-4 )nter the elements into the Lector Step-4.1 for i=> to less than n *ead and stored in aGiH Step-" for i=> to less than TnU Step-".1 !rint the Lector elements aGiH Step-B *ead the element to Ae inserted and print Step-< )nter the position of insertion Step-= Increment n A@ 1 Step-D for K=n to greater than or eOual to pos Step-D.1 aGKH = aGK-1H Step-1> aG--posH = item Step-11 print 6Fector after insertion8 Step-12 for i=> to less than n Step-12.1 print aGiH Step-13 Stop the !rogram PROGRAM .include/stdio.h0 main12 3 int i4K4n4 pos5 float aG">H4 item5 printf1[)nter Si?e of Arra@ Y [25 scanf1[9d[4 :n25 printf1[7n)nter Arra@ )lements Y [25 for 1i=>5 i/n5 iJJ2 scanf1[9f[4 :aGiH25 printf1[7n)nter &eC )lement to Ae Inserted Y [25 aG">H4

scanf1[9f[4 :item25 printf1[7n)nter !osition of Insertion Y [25 scanf1[9d[4 :pos25 nJJ5 for 1K=n5K0=pos5K--2 aGKH = aGK-1H5 aG--posH = item5 printf1[7nArra@ of )lements after insertion Y7n[25 for 1i=>5i/n5 iJJ2 printf1[91>.2f[4aGiH25 ; SAMPLE OUTPUT )nter Si?e of Arra@ Y " )nter Arra@ )lements Y 1 2 3 " B )nter &eC )lement to Ae Inserted Y 4 )nter !osition of Insertion Y 4 Arra@ of )lements after insertion Y 1.>> 2.>> 3.>> 4.>> ".>>

B.>>

(+. AIM: !rogram to print the upper and loCer $riangle of the matriI ALGORITHM Step-1 Start the program Step-2 'eclare a tCo dimensional arra@ aG1>HG1>H4 i4 N4 m and n as 6int8 data t@pe. Step-3 )nter the si?e of matriI and print that si?e Step-4 )nter the elements into the matriI Step-4.1 for i=> to less than n Step-4.1.1 for N = >9@ to less than m *ead aGiHGNH Step-" for i=> to less than TnU Step-".1 for N=> to less than TmU print TaGiHGNHU Step-B for i=> to less than TnU Step-B.1 for N=> to less than TmU Step-B.1.1 if 1i/N2 print 6 6 Step-B.1.2 if1i0N2 print 6aGiHGNH -oCer $riangular ,atriI8 Step-< for i=> to less than TnU Step-<.1 for N=> to less than TnU Step-<.1.1 checK if 1i/=N2 !rint 6$he upper triangular matriI aGiHGNH8 Step-<.1.2 hecK if 1i0N2 !rint 6 8 Step-= Stop

PROGRAM .include/stdio.h0 main12 3 int aG1>HG1>H4 i4 N4 m4 n5 printf1[)nter *oC and olumn of the ,atriI Y [25 scanf1[9d 9d[4 :n4 :m25 printf1[7n)nter )lements of matriI Y [25 for1i=>5 i/n5 JJi2 for1N=>5 N/m5 JJN2 scanf1[9d[4 :aGiHGNH25 printf1[-oCer $riangular ,atriI Y7n[25 for1i=>5 i/n5 JJi2 3 for1N=>5 N/m5 JJN2 3 if1i0=N2 printf1[9"d[4aGiHGNH25 if1i/N2 printf 1[[25 ; printf1[7n[25 ; printf1[+pper $riangular ,atriI Y7n[25 for1i=>5 i/n5 JJi2 3 for1N=>5 N/m5 JJN2 3 if 1i/=N2 printf 1[9"d[4aGiHGNH25 if 1i0N2 printf1[[2 5 ; printf1[7n[25 ; ; SAMPLE OUTPUT )nter *oC and olumn of the ,atriI Y 2 2 )nter )lements of matriI Y 1 2 3 4 -oCer $riangular ,atriI Y 1 3 4 +pper $riangular ,atriI Y 1 2 4 (,. AIM: !rogram for Minar@ search using *ecursion ALGORITHM:

Step-1 Step-2 Step-3 Step-4 Step-"

Start the program 'eclare an arra@ aG">H4 i4 n and loc as TintU data t@pe 'eclare Ain1 2 function as TintU data t@pe )nter the si?e of matriI for i=> to less than TnU Step-".1 *ead and placed in aGiH Step-B for i=> to less than TnU Step-B.1 print Ta1i2 Step-< )nter element to Ae searched Step-= Assign loc=Ain1a4o4n2 Step-D hecK if 1loc==>2 Step-D.1 !rint 6unsuccessful search 9d not found8 Step-1> else Step-1>.1 !rint 6Successful search found8. Step-11 Stop the program *ecursiLe Function Step-1 EloAal declaration of an arra@ A1">2 loC and high Step-2 'eclare mid as Tstatic intU of local declaration and TiU as t@pe. Step-3 mid=1loCJhigh2 Step-3.1 checK if 1Ke@/A1mid22 Step-3.2 high = mid-1 Step-3.2.1 Ain1A4 loC4 high2 Step-3.3 else if 1Ke@==A1mid22 Step-3.3.1 loC = midJ1 Step-3.3.2 Ain 1A4 loC4 high2 Step-3.4 else if 1Ke@==A1mid222 Step-3.4.1 return1midJ12 Step-4 else Step-4.1 return1>2 Step-" Stop the program. PROGRAM .include/stdio.h0 int Ke@5 main12 3 int aG">H4 i4 n4 loc5 int Ain1int *4int4int25 printf1[)nter the si?e of the arra@ Y [25 scanf1[9d[4 :n25 printf1[7n)nter Arra@ elements 1Ascending %rder2 Y7n7n[25 for 1i=>5 i/n5 iJJ2 TintU data

scanf1[9d[4 :aGiH25 printf1[7n)nter )lement to Ae Searched Y [25 scanf1[9d[4 :Ke@25 loc=Ain1a4>4n25 if1loc==>2 printf1[+nsuccessful search. 9d not found. 7n[4 Ke@25 else 3 printf1[Successful search.7n[25 printf1[9d found at position 9d. 7n[4 Ke@4 loc25 ; ; int Ain1int AGH4int loC4int high2 3 static int mid5 int i5 if1loC/=high2 3 mid=1loC J high2#25 if1Ke@/AGmidH2 3 high = mid-15 Ain1A4loC4high25 ; else if1Ke@0AGmidH2 3 loC = midJ15 Ain1A4loC4high25 ; else if1Ke@==AGmidH2 return1midJ125 ; else return1>25 ; SAMPLE OUTPUT )nter the si?e of the arra@ Y " )nter Arra@ elements 1Ascending %rder2 Y 1 2 3 4 " )nter )lement to Ae Searched Y 4 Successful search. 4 found at position 4. (-. AIM: !rogram to Find suAstring of a giLen string

ALGORITHM Step-1 Start the program Step-2 'eclare mainstrG">H4 suAstrG">H as TcharU data t@pe and count4 pos4 i4 N4 len and num as TintU data t@pe Step-3 )nter the main string Step-4 for len=> to mainstr1len2Q=U7>U Step-4.1 print 6ItUs length8 Step-" )nter the starting position of suAstring Step-B )nter numAer of characters in suAstring Step-< checK if 1pos/=> or ount/=> or pos0len2 Step-<.1 print 6)ntracted string is )mpt@8 Step-= else Step-=.1 if 1posJcount0len2 Step-=.1.1 print 6 haracters to Ae eItracted eIceed -ength8 Step-=.1.2 numAer = len-posJ1 Step-=.2 else Step-=.2.1 num=count Step-=.3 N=> Step-=.4 for i = --pos to less than or eOual to posJnum-1 Step-=.4.1 suAstrGNH = mainstrGiH Step-=.4.2 N = NJ1 Step-=." print 6SuAstring8 Step-D Stop the program PROGRAM .include/stdio.h0 main12 3 char mainstrG">H4 suAstrG">H5 int count4 pos4 i4 N4 len4 num5 printf1[)nter the main string 7n[25 gets 1mainstr25 for 1len = >5 mainstrGlenH Q= X7>X5 lenJJ25 printf 1[ItXs length is Y 9d 7n[4 len25 printf1[7nStarting position of suAstring ] 7n[25 scanf1[9d[4 :pos25 printf1[7n&umAer of haracters in suAstring ] 7n[25 scanf1[9d[4 :count25 if 1pos /=> ^^ count /=> ^^ pos 0 len2 printf 1[7n7n)Itracted string is ),!$P 7n[25 else 3

if 1posJcount-1 0 len2 3 printf1[7n7n haracters to Ae eItracted eIceed length 7n[25 num = len-posJ15 ; else num = count5 N=>5 for 1i=--pos5i/=posJnum-15 iJJ2 3 suAstrGNH = mainstrGiH5 NJJ5 ; suAstrGNH=X7>X5 printf1[7n7nSuAstring is Y 9s7n[4 suAstr25 ; getch125 ; SAMPLE OUTPUT )nter the main string muni rathnam ItXs length is Y 12 Starting position of suAstring ] 1 &umAer of haracters in suAstring ] 4 SuAstring is Y muni )/. AIM: !rogram to *eplace A portion of string ALGORITHM Step-1 Start the program Step-2 'eclare mainstrG">H4 repstrG">H4 saLeG">H as T harU data t@pe and i4 N4 K4 pos4 num4 last4 last4 len14 len24 len as TintU data t@pe. Step-3 )nter the main string. Step-4 for len1=> to mainstrGlen1HQ = T7>U Step-4.1 !rint 6$he length of the string8 Step-" )nter position from Chere it is to Ae replaced Step-B )nter numAer of characters to Ae replaced Step-< )nter replacing string Step-= for 1len2=> to repstr1len22Q = T7>U Step-=.1 print the length5 len2 Step-D hecK if 1pos0len12

Step-D.1 for 1i=>2 to less than len2 Step-D.1.1 mainstrGlen1Ji-1H = repstrGiH Step-D.2 len = len1Jlen2 Step-1> else Step-1>.1 last = pos J len2-1 Step-1>.2 N=> Step-1>.3 for i = posJnum-1 to less than len1 Step-1>.3.1 saLeGNH = mainstrGiH Step-1>.3.2 NJJ Step-1>.4 len = N Step-1>." N = > Step-1>.B for i = --pos to less than last Step-1>.B.1 mainstrGiH = repstrGNH Step-1>.B.2 NJJ Step-1>.< for i=> to less than len Step-1>.<.1 mainstrGlastH = saLeGiH Step-1>.<.2 -astJJ Step-1>.= for i = last to less than len1 Step-1>.=.1 mainstrGiH = 6 8 Step-11 !rint *)!-A )' String Step-12 Stop the program PROGRAM .include/stdio.h0 main12 3 char mainstrG">H4 repstrG">H4 saLeG">H5 int i4 N4 K4 pos4 num4 last4 len14 len24 len5 printf1[)nter main string Y [25 scanf1[9GV7nH[4 mainstr25 for1len1=>5 mainstrGlen1H Q= X7>X5 len1JJ25 printf1[7n-ength is 9d7n[4 len125 printf1[7n!osition from Chere it is to Ae replaced ] Y [25 scanf1[9d[4 :pos25 printf1[7n7n&umAer of characters to Ae replaced] Y [25 scanf1[9d[4 :num25 printf1[7n7n)nter replacement string Y [25 9s[4 repstr25 for 1len2=>5 repstrGlen2H Q= X7>X5 len2JJ25 printf1[7n-ength is 9d 7n[4 len225 if 1pos 0 len2 3 for 1i=>5 i/len25 iJJ2 mainstrGlen1Ji-1H = repstrGiH5

len = len1 J len25 ; else 3 last = pos J len2 - 15 N = >5 for 1i = pos J num - 15 i/len15 iJJ2 3 saLeGNH = mainstrGiH5 NJJ5 ; len = N5 N = >5 for 1i=--pos5 i/last5 iJJ2 3 mainstrGiH = repstrGNH5 NJJ5 ; for 1i=>5 i/len5 iJJ2 3 mainstrGlastH = saLeGiH5 lastJJ5 ; for 1i = last5 i/len15 iJJ2 mainstrGiH=X X5 ; printf1[7n[25 printf 1[*)!-A )' string is Y 9s[4 mainstr25 printf1[7n[25 ; SAMPLE OUTPUT )nter main string Y muni rathnam -ength is 12 !osition from Chere it is to Ae replaced ] Y 1 &umAer of characters to Ae replaced] Y 4 )nter replacement string Y mani -ength is 4 *)!-A )' string is Y mani rathnam

You might also like