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

C Programming Lab

Notes

Uploaded by

shenazd17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
16 views

C Programming Lab

Notes

Uploaded by

shenazd17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 39
CONTENTS CONTENTS CORE LAB - I: PROGRAMMING LAB-C 2b-09-B f | Ex.No. Date = Title of the Program ae I: cotas| 8 4 06-07-13] SUM, AVERAGE & STANDARD DEVIATION | @ } 2. | 15.9f.93| PRIME NUMBERS V O4 | 3. 1309.07.95] FIBONACCI SERIES 1 OF \ 4. | oh 08.93| MAGIC SQUARE " 5. N08. 23 ASCENDING ORDER 1a 6. |Q)-05.45| PALINDROME 4 7. |94, 0g.a6 | COUNT THE NUMBER OF VOWELS on 8. |ol-pg.g3| FACTORIAL USING RECURSION os 9. | 95-09-93) STUDENTS MARKSHEET 2 | | 10. [09.09.28 MATRIX ADIATION 30 | 1 | yeoa-a3] TO CHECK FILE CONTENT IS SAME OR NOT | 33 Copy AND DISPLAY FILE DETAILS ab = = | 61 13038 BUM AVERAbIE AND STANDARD PEVIATION AM | To wok ¢ Program to fird The Sum, Average and Standand deviation fen a given Sot ef Numbew ALGORITHM Step |: Stott the pros Step a: Hwlaning the Vostable . Enter the inpuk Vals Step 3: Caladale The Sun and average fon ‘The giver Numbers Step 4: Calaudtte the standard dovieition using formula. Shp 5 : paink the Saf, cxteray and @tandavidl deviation Step 6: atop “the Ps Less Te ee ee ee: ernest oe ee gee ote ee eM Rn eS ae ee Ex. No: 1 I JERACE /* SUM, AVERAGE AND STANDARD DEVIATION */ #include Hinclude #include void main() int a,b,c,d; float e,f,s; clrser(); print{("Enter three values"); scant("%d%d%d",&a,&b,&e);, d=atbtc; printf("The Sum is %d \n".d), e=(float)d/3; print{("The Average is Yl \n",e); fH ((ave)*(a-e)+(b-e)*(b-e) Hee)"; s=sqr(; A printf("The Standard Deviation is %f \n",s); 7 getch(); OUTPL Enter three values 4 6 8 The Sum is 18 The Average is 6.000000 The Standard Deviation is 1.632993 RESULT: Thus Whe above Program hos Weon precited » / ee 7 Z| 6 a AIM ® = Step at ~ acs g + SHSVIRHSSSSSOSSSSSSSSHHSHSS wD ® & ges - Lo) § a &® 2 SHOSHSSHOSSHSSSSGGS bate 1%) 04} wl PRIME NUMBERS To wre a ¢ Program to generle prime Num betwen the given number ALGORITHM ~ Start the Prous : Eni a& Number fil yeu neal fo Print tre + Use while Statment 0 while (i Zn) , Use fon Loop Statement cus lhon C5285 5 4247544) + chek ib (hz jes0) the susult is not pxime 2 Else paint prime Number whil: tondition is 2 Stop THe process Pedasiing the vortable ie 1-255, Prime Number SOPHO GSSSSTSSSSISHSHSHSHSSOSHOHS Number it bc=1) 399999550000000009000000 _ a nmegooooooe | | Ex. No: 2 /* PRIME NUMBERS */ #include void main() ‘ int = 2j.cn; clrserQ); printf("Enter number till you went prime numbers”): scanf("%d" ,&n); printf{("Prime numbers are: \n"); while(i<=n) ‘ oo, for(j-25<-15) /\ f | t os / | ifG%j=9) J ot / ee if( =) printi("%d\n" i); . OUTPUT: Enter number till you want prime numbers 25 Prime numbers are: UBD ll 13 17 19 23 A.V.P. COLLEGE OF ARTS AND SCIENCE, TIRUPUR [4 _ SooKeseoousessEoOUDESEOTsO0OGeR0 <4 N i ExNo: 3 pate 20)04 } FIBONACC! SERIES pogeoecoooooseess AIM To wrk a ¢ Progam to gener the . {ibonaui Sees ter giver N numboxt : ALOORITHM 8 Sp): Slant the powws Botp a: Dulane the variables i, num, § Sr 8 Stop 3: Tnitraltge the vosiiabdl & $+ 0,S=! g Slap print the vole fon num g shy: use fon Lleep Slakmont fonli= 95) £nwm, 147) Shp 6: Assign values ir N= brs, #2 &, Sen Baty: print the vali of N @ Step g: Stop The prpuss Te ene 'SSGSSOSSo Ex. Nor 3 /* FIBONACCI SERIES */ #includesstdio.h> Hincludesconio.h> void main() { int ium, f=0,8= Ln; clrser(Q; printf("Enter how many numbers"); scan{("%d",Snum); print{("FIBONACCI SERIES \n");, printf("%d\n",0; print{("%d\n",s); ;i # include void main() { int n, i,j, caf 9119] 5 clrser() ; print{("Enter magic square size(odd)") ; scant("%d", &n) ; printf("\n Magic square\n") 5 je(nt+ 1/25 i=l; for(c= 1; ¢<=n*n3ctt) t afiJL)=°3 if(c % n == 0) | { | i=(+/1); goto loop ; c died tales loop: ; 4 for (i= 15i<=n; i++) ( for G=13;j<=n3j+4) t printf(%d\t", afi}Li) s } 7a Bae i ; } getchQ) ; ow IT; Enter magic square size (odd) 3 Magic square 8 1 6 <) 5 7 4 9 2 Tus the dhove Progam hos buen eeuded sully / one \ 12. >| Sah eet [Date N18 Javas ASCENDIN t1 ORDER iP a Weill a ¢ Program +o Bonk Tie given Sek eh Numbers in Asunding onder. ALGORMHM s Stop): Stok the prow b Shap 2: Liter Me Numbuu +o be ondened 3 stop 3: Chetk the Semone of fout toe Nambu ® stop 4; Th The Numbeu i Small than intercharge kk A ® Stop 5, Repeat The oof fp Al Numba Step bs Stop the pros Ex. No: 5 /* ASCENDING ORDER */ d#include #include void main() { int a6); int ijn: elrserQ); printf("Enter the input \n"); for(i=0;i<6ri+4) seanf("%d" &ali)); for(i=0:i<6;i++) { for(j=it Li<6+4) ) iftatil e 8 gop + 1h Te TeVOUE cae 8 ap is a reverse o ghing 1 dipjpent Tren sh is Not padi Biop 6: Stop “The pao 1@SSS99GG009 gx. No: 6 ie PALINDROME */ #include #include void main() t char *a[20], *b[(20); clrser(); printf(“Enter the String: \n”); scanf("%s",&a); strepy(b,a); strrev(b); if(stremp(a,b)==0) { printf("%s is a Palindrome", a); /) else printf("%s is nota Palindrome”, a); oe es getch(); ourpur: Enter the String: MADAM MADAM is a Palindrome Enter the String: HELLO HELLO is not a Palindrome RESULT: / above pacotam has ben excused Success pully e aie" ee é = sala COUNT THE NUMBER OF VOWELS Dai ss a J bet Jo Write C program +o teunt the Num ef vowels 4n Jiven ortenve SWAG Ve osv20000 @ ALwOkITHM 8 gupi 2 Stal the prows ; o oo Ltn the Sing chuck for The vous chances a, o.1+0 gst 5! reunt The vowel and / Les x Stop The /Pno U paint Them 8 sup e on = a SESSVSESSSIOVSIVSSSOGR ps. NO 7 / COUNT N E NE NUMBER OF VOWE ELS */ yincludesstdio h> zincludesconio.h> void main() { char a[50}; int c=0,i=0; clrserQ); printf("Enter the String: \n"); gets(a); while(a[i]!="0) { if(afi}-= I alt "yj + file“ [all iJ aliJ==E' Il afij==7 lI afi afiJ-"U) cH / / i++; ~ i Js are 904", c) printf("The number of vowe! getchQ; Enter the String: This is my seventh Program The number of vowels are 6 / ESULT: // ioe bd SU . Cc ~ \a \4 =~ weg ISA aE eee Og SCIENCE, TrRUPUR [23 No \2 Seeee00s000! To Write ¢ Program 4p find ite fautonial of ouci Nuwmbot Uking Hewwawve funchion j)boRITHM slop 12 Stank /Ma prow g tp a: Enter pow many Numbews ane rained hee Caleutate the fautonial Values OA nlc it BE Bee the pros OVEeooeowoeoaq = NS w s ~ ps. NoF 8 rae ae etna PAC * “FACTORIAL SIN: RIC RIAL Us Us G RECY i SION yinclude sinclude yoid main() ‘ A int n; clrserQ); printf("Enter how many numbers\n"); scanf("%d" ,&n); ‘ printf("Factorial is %d" fact(n)), getchQ; } fact(int i) { int f / if(i==1) / return 1; else ‘ fei*fact(i- \)s return f; Gs ue Enter how many numbers 5 Factorial is 120 uLT: nese / Thus The above Program hos bun exewuled & | saOs teen ©, TIRUPUR (ae ] Seeeeae0a0s ABORT HM ‘shp 1: SFO The prow ; gop a: Eris the Roll No, Name and five subyats | Mastk ef Sudents sup Bi USE covlay of Shut fon Storing the | daka- / Shp. : print “the ae Shek of, The all Ghideds shy 5, Stop The/ Prous Not 9 (24 ; * STUDENTS Ma # include #include int a[3][3],b{3[3}; void add(int(*)[3}); void main() { int ¢[3)[3], ij; clrser(); printf{("Enter A matrix \n"); for(i=0;i<3;i4+4) for(j=0:j<33j++) scanf("%d" &ali}[)); printf("Enter B matrix \n"); fort for si<3i+4) 0;j<3.j+4) scanf("%d" &b[iJLi))s add(c); printf("Addition \n"): for(i=0;i<33it) : { i for(j-0:5<3:4) J f t printfa" Li]EDs ) printf" } getch(): void add(int e[3]3)) for(i=0;i<3 i++) for(j=0;}<3,j++) CHGali i +HTIG); ouTPUT: gourre*: Enter A matrix red 12 ete 1 1 i 2 2 2 Enter B matrix 3a Om 303 3 2 2 : Addition ome 4 4 ¢ 4 4 : agus / Via am has boon eveuted J 1 ; ee oes unesipally LTT TT TIRUPUR [ag ee oo | Bien: Tq 880000009 oO T Boat njajooos) 1° CHECK FILE congent 'S SAME OR eq ls fot Wee : \o —¢ 8 AIM 8 eee Jo write OC Progam so suutive fhe warns ae angumuts and chou whether and file tentenl 8 aw Sarre oY Not and deleting ene file if, both 8 aw Same e a @ ® @ ® e e a o : : 8 ALDIORITH M 8 @ skp 1: Stovtt the Pros 8 @ obp a: Evi two files namu threugh lornmand é 8 dune cotqumertts 3 § Stops: Open wo file sn Mead mode 8 e 8 Shp4: oad the Levilent of both ils $ one» Pont the filer are 2 8 Stops: If oth oe : 4 ‘ { 4 :) . 4 donk cal and. delele the Suend fi Le s ° « eles ae not identical & P 2 paint ti 3 step 6: Othowu a $ close the Kle/ @ Stop Ae J og. Step the /prouwt : Stop 8: J & e ea! -,.No: Ht ra mall / TO CHECK FILE TENT T ILE CONTEN 1S SAME OR NoT+/ Hinclude void main(int arge, char *argy[]) ‘ { FILE *f1, *f2; char cl, ¢2; fl=fopen(argy[1],"r"); £2=fopen(argv[2],"r"); cl=fgete(fl); c2=fgete(f2); while((cl !=1 { cl=fgete(fl); c2=fgete(f2); OF )&&(c2!=EOF&&(cl==c2))) } if(cl==c2) { printf("Files are identical wn"); remove(argy[2])5 printf("Second File deleted \n"); i else { y printf("Files are not identical \n"); } felose(fl); felose(f2); getchOs 5 Oe eg eer C’\ progll aac bb.c Files are not identical C:\ copy aa.c bb.c C:\ progll aac bb.c Files are identical Second File deleted / RESULT: / abeve Program Was bun exeuiled Suse SSSR = s ° Ys gE : : Step 6: Co & FSSSSPSOSSHSOSSIOHOSSSSIOGSSHSSSSTOGGSE SONNE R0000 a ExNo: 12 SSSR Eg pate ab A bog TO wrth a ¢ Progiam wing Lerman June corgument and topy it to anotrer file and nine The nevesevy dcldle ef the foes ALbroRNHM COPY AND DISPLAY FILE DETAILS e0oe Stank the Prous Evilet the file Name tiveugh Lornrranc open One fie in Sead Mode and another % night roode Read the torent ef fle) and wrk the Loilent ‘in file 2 | Ad the end point Ane Numb chanacttous , words and din in the bk clese The file ; gtop the pros sx, No: 12 i Ex. No: /* COPY AND DISPLay FILE DETAILS */ #include void main(int arge, char *argy(]) f ' FILE *f1, *f2; char ch; int c=0,w=0,1=0; fl=fopen(argv[1],"r"); £2=fopen(argv[2],"w"); ch=fgete(fl); while(ch!=EOF) ¢ fpute(ch,f2); ett; if(ch==""); wit; if{ch—='n) / | { / | H+; / wits / } / ch=fgeto(F 1); \ 5 felose(f1); PHin{("\n File copied to %s" argy[2)); Print{("\n Total no. of characters =%d",¢); printf("\n Total no. of words =%d" yw) Print{("\n Total no. of lines =%d"1); getchQ); OUTPUT: CA progl2 aac bb.c File copied to bb.c Total no. of characters =245 Total no. of words =160 Total no. of lines =19 Thus “Gove progiant has been eeu

You might also like