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

C Program Manual 1BCA

Uploaded by

Aushik Hirani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
25 views

C Program Manual 1BCA

Uploaded by

Aushik Hirani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
Problem Solving Lab Using € 1. to read radius of a ci | #include K #include f void main() { float r,area, circum; alrscr(); printf("\n Enter radius of a circle :") scant("%ef", 80) area=3.142*r*r cireum=2°3.142"r | printf("\n Area of a circle = fin Ciroumference of a circle = %f \n" area, circum) getch() Output, | Psa SNC NE MSs rey frea of a circ Re RcroN epee sacri tes Nem Ceres 2. to read three numbers and find the biggest of three | #include void main() (i int n1, n2, n3; clrser(); | printf("Enter three different numbers: ay; | scant("%d%a%a", nt €n2.83) | | if (n1 >= n2.8&n1 >= 03) printf("%éd is the largest number,", n1) if (n2 >= n1 && n2 >= n3) printf("%d is the largest number.", n2); if (n3 >= nt && n3 >= m2) printf("%d is the largest number.", 13); | Government First Grade College, Vijayanagora ee © scanned with OKEN Scanner ee Oe Pe mney Seams SE Cea scr Sa oae 3. to check whether the number is prime or not #include #include | void main() int num,count=0,i | elrser(); printf("\n Enter a number : ") scanf("%d",&num); for(i=1;i<=num;i++) { | if(numy count++: } if(count==2) | printf("\n 9%d is a Prime number",num); | else | printf("\n %d is not a Prime number’,num): getch(); me! eee ee sc ace _ © scanned with OKEN Scanner yo iSeries Si SaaS Catia 4. to rea palindrome # includestdio.h> # include void main() int num orgnum int sum=0,rev=0,rem, clrser() print(\n Enter a number :") scant("%d", num): gnum=num; while(num>0) rem=num% 10; sum=sum+rem; rev" 10+rem: print{("\n Sum of digits = 96 printf("\n Reversed number = % i(orgnum==rev) printi("\n Number is a Palindrome’); print{("\n Number is not a Pa getch\); ee eM SEL) SC ae eevee mt ea) Te cue rae tent nea jernment First Grade College, Vijayanagara 'd a number, find the sum of the digits, reverse the number and check it for Page [3 © scanned with OKEN Scanner oe et Sum of digits = 4 coe eC Number is a Palindrome_ -esses 999 and to find the to read numbers from keyboard continuously till the user pr | sum of only positive numbers # include | #inctude void main() | int num,sum=0; clrser() do { printf(\n Enter a number :") scanf("%d", &num); if(num > 0 &8& num! 99) sum = sum + num: print("in Sum = Yd”, sum); while(num!=999), printf("\n You have pressed STOP"); getch() res nt Fit sais College, Vijayanagara Page Ta © scanned with OKEN Scanner . to read per else-if ladder | Program to Demonstration (/ Pereontage > 90% BO% ~ 90% 70% = 79%, 60% ~ 69% 50% - $9% 38% = 49% wemtage of marks and to display appropri Ml percentage of marks andl to oF Colye-if) ladder Grade Exemplary Outstanding Division with Distinet rst Division Second Division Pass class Reappear | # includesstdio.n> | incudesconio | void main’ { | float per; clrser() printf('\n Enter Percentage : ") scanf("96"",&per); (per > 90.0) printf("\n Grade = EXEMPLARY"); else if(per >=80.0 && per < 90.0) | _ printf(\n Grade = OUTSTANDING") else if(per >=70.0 88 per < 80.0) else if(per >=60.0 && per < 70.0) printf("1n Grade = FIRST DIVISION") else if(per >=50.0 &8 per < 60.0) | printf("\n Grade = SECOND DIVISION’) | else if(per >=35.0 && per < 50.0) printf("Wn Grade = PASS CLASS"). else printf("\n Grade = FAILS : RE-APPEAR’) getch() } Qutput Bec con ron Government First Grade College, Vijayanagara print{("\n Grade = FIRST DIVISION WITH DISTINCTION") ene ¢ message (Demonstration of display appropriate message Page [5 © scanned with OKEN Scanner . to find the roots of quadrat cy Grade = OUTSTANDING Cen eer) SUSUR TMS Le Paced CSS Una) oo aes) Grade = SECOND DIVISION ery Grade = PASS CLASS Pree eet Grade = FAILS : RE-APPI equation #include #include void main() { float a,c float d,roott 0012 celrscr(); print("Enter db and of quadratic equation: *) scant "tr Ba, 8b,8c) d=b*b-4*a'e if(d < 0) { printf("Two distinct complex roots exists: ") 3% f-i(2"8) sart-a)}2"2)) printf" printf, %.31%+.3M"-b/(2*a),-sqrt(-d)(2"a)); © Scanned with OKEN Scanner ) Problem Solving Lab Using ¢ else it(d==o, ( TOOtt = -b /(2* a) Prnt(Two equal and realroot xi { Ott = (-b + sart(ay) /(2* a FOOK2 = (-b - sqrt(d)) / (2° a Brot cstinet and real rots exists: 6.31, %.9° root soo getchi) Queput: f quadratic equat x roots Cee Fy 8. to read marks scored by n students and find the ay ‘erage of marks (Demonstration of single dimensional array) # include # include void main() It ni float marks[10), tot_mark: O,avg_marks=( clrsor(): | printf(\n Enter students count(n) :") | scanf("%d",&n) | for(i=t : printf("\n Enter mark scored by %d student : "+1); scanf("%f",amarksil); ji # include void main() i int a[20},n.i,j.ele: clrser() printf("\n Enter array limit(n) scanf("%d",8n); for(i=0;l # include void main() int a[10](10}, b{40)[10}, o{10}(10}, 4(10](10}; inti | Government First Grade College, Vijayanagara “rage © Scanned with OKEN Scanner Problem Solving clrsert) Brinn Enter order of aquare mattix(n) :*); Sscant(“P0",8n), Drint("\n Enter A matrix eloments\n" for(ieO;kenie+) { fori-0; # include void main() =1,NXT; int FC clrser() printf("1n Enter series limit(n) scanf{"%d",&n); printf(" FIBONACCI SERIES * print{("%d \t %d"\F,S); for(i=3ji<=nii++) x NXT=F+S) Printf("t %d", NXT); F=S; S = NXT, getch(); Pag © Scanned with OKEN Scanner - Problem Solvins 7. co find the length of vk a string w Ms Without using built in function # include # include void main() intlen=0, char *str: | ctrsex) print Enter asrng:*) ‘scanf("%s" str); whie(st=%0) lens ) | brintin Length of sting = %d"Ien) | getcno) ETS | ee st ea) 14. to demonstrate string functions # include #include # includecstring.h> | void main() 3 | { | char ‘str1="Bangalore" clrscr(); | printf("n String 1 = %s String 2= %s\n"strst2) | | char “str2="Universit print("\n 1. Length of %s = %d".str1 strien(strt)); | printf("n 2. String copy in str2 = %s",strepy(str2,"CITY")), printf("1n 3. Concatenation = %s", streat(str4,str2)); printi("in 4. Compare str1 & str2 %d",stremp(str1,"bangalore")); | printf("in 6. String in upper case = %s",strupr(str1));, | printf("n 5. String in lower case = %s",striwr(str1)); | | printf("in 7. Substring search = %s" strehr(str1,'L); printf("\n 8. Duplicate string = %s" strdup(str1)); ‘Government First Grade College, Vijayanagara Page [13 © scanned with OKEN Scanner Jerse = %s",strrev(strt)) print{("\n 9. String re’ fe printf("\n 10. Set all character to # = %s" strset(str1,# getch() ) Output. Se Ma Tm a ee ee ae) String copy in str2 = CITY Concatenation = BangaloreClTY + Compare stri & str2 -32 Su OMe meres a eee ren oh een at : Piven Rater) SSC ec esti 15. to read, display and add two m x n matrices using functions #includestdio.h> Void muttiply(int matt[12}{12} int mat2{12}(12)int it nt void main() int mat4[12](12],mat2[12][12} intijkim.ngp: clser(); Printf("Enter the number of rows and columns for 1st matrix\n’’ scanf("%d%d" &m,&n); printf("Enter the elements of the matrix\n") for(i=0;i #include # include void main() { : ; t char str100} oh; int acount=0, deount=0, veount=0, ccount=0, scount=0, spcount=0 i=0; | clrser(); | printf("\n Enter a string :"); | gets(str); | white str a college, Vi ae rage TIE Government First Grade College, Vijayanagara © Scanned with OKEN Scanner else iffisdigit(stt else iflisspace( acount++ ch=tolower(str() case 'o case 'U': veount++ dcount++ print getch( n No. “Government First Grade College, Vijayanagara 0. of Vowels = %d 0. of Spaces sti) of Alphabe "acount of Consonants = 2 count) Digits = %d" dcount of Special symbols = %d", spcount) ee ecco d Peer a Problem Solving Lab Using C Page 117 a © Scanned with OKEN Scanner 17. to Swap Two Numbers using Pointers # include # include void main() int 1,n2,*ptr1 ,*ptr2,temp: clrser() printf("\n Enter two numb scant(""%d %d",8n1, &n2) printf("\n Before swappin | ptri=ant liswapping temp="ptr1 *ptrt="ptr2; *ptr2=temp: printf("\n After swapping n1 = %d_n2 = %din’,n1,n2); | getch() Govern’ iment First Grade College, Vijayanagara © Scanned with OKEN Scanner fi inowde Problem Solving Lab Using C o demonstrate student structure to re ‘ad & display records of n students (54h include struct STUDENT { int regno; char name(50} | char grade; | 8cA(s0); | void maing) r ) intr | clrscr() brintf("\n Enter student countin) :") | scanf("%d",&n) for(i=Qiicni++) { | printf('n Enter %d student(regno,name,grade) :" i+); | seanf(Y6d %s He", BBCAl].regno BCA name, BBCA] grade) printf("in REGNO \t STUDENT NAME \t GRADE") for printf("\1n %¢ \t %s \t 9c", BCALi}.regno, BCA name, BCAIi].grade) getch() Mee can Pee ec nr cc) Pee Toners Len aa | a f | ery Peo 1 ar f r a ry Toe cae ynagara Government First Grade College, Vlayanaga ov © Scanned with OKEN Scanner Problem Solving Lat between structure & union. 19. to demonstrate the difference # inolude { t bot intempid; 12 bytes 4 char name{50}; // 50 bytes nae loat salary; 4 bytes (Total =2 + 50 + 4 = 56) u } union EMP2 int empid; 1/2 byt . * 114 bytes (highest = 50 bytes) void main() ¢ ( £ clrser) F : { Print{("In Size of Structure EMP1 = %d" sizeof(struct EMP1)) printf("1n Size of Union EMP2 = %d",sizeof(union EMP2) getchi); age escieame ll © Scanned with OKEN Scanner Goverr rnment First Grade College, Vijayanagara

You might also like