0% found this document useful (0 votes)
62 views35 pages

C Assignment

C assignment . Common c example for programming

Uploaded by

MD Sumon Hossain
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)
62 views35 pages

C Assignment

C assignment . Common c example for programming

Uploaded by

MD Sumon Hossain
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
cS) Khulna University.of Engineering & Technology (KUET) Assignment on: ME-2221 Submitted to: Dr. Md. Kutub Uddin Professor Q Department of Mechanical Engineering ahs Khulna University‘ot Engineering & Technology” & (KUET) > > Ss S © Submitted by: Aniruddha Roy Protya Roll: 1805032 Department of Mechanical Engineering Khulna University of Engineering & Technology (KUET) Date of Submission: 10 June, 2021 Y” Y S we ME-2224/Assignment) Pa, oj 1 Problem 1. Given 10 values X, find the biggest of them. Program: #include void main() { int 4, a[100], big; printf ("ENTER 10 INTEGER NUMBERS: \n"); for(is@; ict@; i++) scanf("%d", Ba[i])5 big = af]; ice; i++) if(big < a[i]) big = a[i]; printf ("The biggest value = %d", big); Problem 2. Given 10 values X, find the smallest of them. QR & wielude mia main() { int i, a[100], small; printf ("ENTER 1@ INTEGER NUMBERS: \n")5 for(is0; ict@; i++) scanf("%d", &a[i]); small = a[0]; for(ino; ice; itt) if(small > a[i]) small = afi]; print#("The smallest number = %d", small); Problem 3. Given 10 values X, find the biggest, smallest values and the range value. Program: #include void main() { & ce & ME-2224/Assignment) int 4, a[100], big, small; printf("ENTER 10 INTEGER NUMBERS: \n"); for(i=0; icl0; i++) scanf("%6", @afi]); small = [2]; for(i=0; ice; itt) if(small > a[i]) small = a[i]; printf ("The smallest number = %d\n", small); big = af]; for(i@; ito; i++) if (big < a[i]) big = ali]; printf ("The biggest value = %d\n", big); printf ("Range values: %d to %d", small, big); R Profigh 4. Given 10 values X, find the mean. _ CO a Rad 5 Program: OS Q #include main() { int i, a[100], s=0; float mean; printf ("ENTER 1@ INTEGER NUMBERS: \n"); for(is0; ito; i++) scanf("%6", @afi])3 3 ice; is) sesta[i]; mean=(Float)s/10; printf ("Mean = %.3#", mean); for(: y Problem 5. Given 10 values X, find the mean of the values, which do not exceed 35. Program: #include main() es ro R ME-2224/Assignment) Pa, oj 3 int i, a[200], s=0; float mean; again: { printf("ENTER 16 INTEGER NUMBERS: \n"); 3 icles i++) a", Ba[i])3 5 10; i+) sestali]; mean=(float)s/10; > if(mean>35) { printf("Mean is greater than 35, so enter value again\n"); goto again; + print#(°Mean =f", mean); rrapeet Given 10 values X, find the mean of, yeMues, which lie between 27 and 53 tac inelusive. sf RS < S #include main() f int 4, a[100], s=0; float mean; again: t print#(“ENTER 16 INTEGER NUMBERS: \n"); for(i=0; ice; i++) scanf("Xd", Ba[i]); For(ind; ica; it) ses¢ali]; mean=(float)s/10; + if(mean>=27 && mean<=53) { printf("Mean doesnot lie between 27 and 53, so enter value again\n"); goto again; 3 print#("Mean = %#", mean); & ME-2224/Assignment) Pa, oj 4 Problem 7. Find the sum of 1000 natural numbers i.e, positive integers. Program: #include void main() { int i, s=05 for(i=1; ic#1000; i++) sestij print#("The sum of 1000 natural numbers = %d", s)5 t Problem 8. Find the sum of all odd integers from 1 to 1000. Program: #include void main() printf("The sum of all odd integers from 1 to 1000 = %d", 5); Problem 9, Find the sum of all even integers from 1 to 1000. Program: #include void main() printf ("The sum of all even integers from 1 to 1000 = %d", s); & oo & a & Y” Y S we ME-2224/Assignment) Pa, oj 5 Problem 10. Find the sum all integers divisible by 3 from 1 to 1000. Program: #include void main() { int 4, 5205 =1000; i++) printf("The sum all integers divisible by 3 from 1 to 1000 = %d", s); Problem 11. Find the sum of all integers divisible by 5 from 1 to 1000. Program: #ini stdio.h> win ) & “ , Ss =1000; i++) 9 if ((i%5)==0) sesti; + printf ("The sum all integers divisible by 5 from 1 to 100@ = Xd", s)5 Problem 12. Given 10 values X, find the mean of the values, which are integers. Program: #include main() { int i, s=0, a[100]; float mean; printf ("ENTER 1 INTEGER NUMBERS: \n")5 for(i=0; ice; i++) scanf("%d", &a[i]); 3 ice; i++) ME-2224/Assignment) Pa, oj 6 sesta[i]; mean=(Float)s/105 printf ("Mean of the values, which are integers = %.3f", mean); Problem 13. Given 10 values X, find the mean of the values, which are nonintegers. Program: #include main() t int i, s=0; float mean, a[100]; printf ("ENTER 10 NONINTEGER NUMBERS: \n"); 3 ice; in) scanf("%F", Ba[i]); 3 ice; in) sssta[i]; meang(Float)s/10; infect F("Mean of the values, which are esters = %.3f", mean); & oO oO oO Problem 14. Given, 10 values X, find the mean of the values, which non-integers, not exceeding 95. Program: epuercngir main() { int i, s=0; float mean, a[100]; printf ("ENTER 10 NONINTEGER NUMBERS: \n"); for(ind; ice; i++) scanf("%F", &a[i]); for(i=0; ice; itt) { if (ali]<=95) sestali]; + mean=(float)s/10; printf ("Mean of the values, which are nonintegers, not exceeding 95 = %.3f", mea a)3 R SR os oS a Yo oi SO ME-2224/Assignment) Pa, 17 Problem 15. Given 100 values lying between 0 and 25, sort the values into a frequency distribution with five equal class intervals, the right-hand limit being always inclusive. Program: #include main() { int i, c=0, d=0, e=0, fa float a[109]; printf("Enter 100 values between @ and 25:\n"); for(i=0; ice; itt) scanf("%F", &a[i]); for(in0; iclee; itt) { if(a[i]<=0 8& a[i]<=5) cH else if(a[i]<=6 && a[i]<=10) des else if(a[i]<=11 @& a[i]<=15) et; e if(ali]<=16 @& a[i]<=20) R fees oS OV else if(atil<=21 8& afi}<=25) Se < SY else SY continues } printf ("frequency distribution with class interval @ to 5 = %d\n", c); printf ("frequency distribution with class interval 6 to 10 = %d\n", d); printf ("frequency distribution with class interval 11 to 15 = %d\n", e); printf ("frequency distribution with class interval 16 to 2 = %d\n", ); printf (“frequency distribution with class interval 21 to 25 = %d\n", g); Problem 16. Find the sum of inverse of 1000 natural numbers. Program: #include void main() { 10005 i++) sesti/is printf ("The sum of inverse of 1000 natural numbers = Xf", s); R R e Fo) oO SY ~ _& Y” Y S we ME-2224/Assignment) Pa, oj 8 Problem 17. Find the sum of factorials of 10 natural numbers. Program: Hinelude #include int fact(int n) { int i, fa; for(i=1; return f5 + void main() { int i, a[100], s=0; printf ("ENTER 1@ INTEGER NUMBERS: \n")5 For(i=0; ic; itt) scanf("%d", &a[i]); & Acie; i++) fact(ali]) 3 Ne he “ oO ‘ ‘DY Problem 18. Find the sum of the series: oS: +i- “+ 1000 terms © Program: #include #include void main() { int i; float for(i=1; ic=1000; i++) s+pow(-1,441)*1/1; printf ("The sum of series = %f", s); + Problem 19. Find the sum of the series: 1+1+24+3+54+8+13+~ Program: #include void main() { & ce & Y” Y S we ME-2224/Assignment) Pa, oj 9 $0, fls0, f2=1, fel; 5 ic=205 int) printf("The sum of Fibonacci series = %d", s); Problem 20,Find the sum of the series: 1 +.5 +.5? +59 +.5¢ +.55 + “12 terms: Program: include include void main() { int 4; Floarys-0; & 5 Leds Ate) S&S <6 =sipou(0.5, 4); oO Oo a Nprintf("The sum of series = Xf", 2 “~ co ro Problem 21. Given three numbers, A. B.C prints them in an ascending order. Program: #include void main() { int A, By C, a by ¢3 printf ("Enter three numbers A, B, C: scanf ("Xd %d %d", 8A, &B, 8C); if(AyB && A>C) { if (B>C) print#("Ascending order: %d %d %d", C, B, A)5 else printf("Ascending order: %d %d %d", B, C, A); 3 else if(B>A && B>C) { if (A>C) & or NS Pag& 10 Rell) 1805032 print#("Ascending order: %d %d %d", C, A, B)5 else printf("“Ascending order: %d %d %d", A, C, B); 3 else { if (ADB) print#("Ascending order: %d %d %d", B, A, C); else print#("Ascending order: %d %d %d", A, B, C)5 + Problem 22. Given three values A. B. C. prints them in a descending order. Program: #include void main() B, C, a, b, c5 { int maa Ccenter three numbers A, B, C:"); S&S inF("%d %d Xd", BA, BB, BC); Oo SS if(are 8& Ac) ~ St Ss if(B>C) printf("Descending order: %d Xd %d", A, B, C); else printf("Descending order: %d %d %d", A, C, B)5 } else if(B>A && B>C) { if (A>C) printf("Descending order: %d %d %d", B, A, C); else printf("Descending order: %d %d %d", B, C, A); } else { iF (A>B) printf("Descending order: %d Xd %d", C, A, B); else printf("Descending order: %d %d %d", C, B, A); } & < ME-2224-(Assignment) Problem 23. Given 10 values in list X, sort them in an ascending order. Program: #include void main() { int 4, J, a[100], temp; printf ("ENTER 10 INTEGER NUMBERS: \n")5 for(ind; ice; i++) scanf("%d", &a[i])5 for(i=0; ic; itt) for(j=itt; 4<10; j++) if(a[i] > a(i]) { temp = afi]; ali] = al3]s ali] = temp; ) } prin “ascending order:"); R és 5 110s i++) intf("\t%d", ali])5 “~ SY Problem 24. Given 10 values in a list X, sort them in a descending order. Program: #include void main() { int 4, 4, a[1¢2], temps printf("ENTER 10 INTEGER NUMBERS: \n"); For(i=03 ici@; i++) scanf("%é", &ali]); for(is0; ict@; i++) for(j=it; j<105 j++) if(a{i] < alj)) { temp = afi]; afi] = af3]; a[j] = temp; + + a NS Pag, S I Rell) 1805032 & & RS x anit we a we Oo void main() { int i, j, a[100], temp, si=0, s2=9; float m1, m2; printf("ENTER 10 INTEGER NUMBERS: \n"); for(: ic10; i++) scanf("%d", &a[i]); 3 ic10; i++) j=i+1; j<10; j++) R R CS sft] > ats oe co { x temp = afi]; © a{i] = ali]; SY a[3] = temp; for(i=0; ic; i++) si-si+a[i]; m1=(Float)s1/55 for(i=5; icl@; i++) s2=s2+a[i]; m2=(Float)s2/55 printf ("the mean of the smaller five values=%f\n", m1); printf ("the mean of the five bigger values=%f", m2); Problem 26. Given 11 values in a list, find the middle value when arranged in order of magnitude. Program: #include void main() { & oo Oo abs(al3])) { temp = afi]; afi] = af3]i a[j] = temp; + + printf ("the middle value when arranged in order of magnitude: printf ("%d", a[5])5 Problem 27. Given 11 values, find the subranges from the lowest value to the middle one and from the middle value to the highest value. meh & : oO = ude afj]) { temp ali] ali] ali]; ali]s ‘temp; + } printf("the subranges from the lowest value to the middle one is %d to %d\n", a[0], a[5])5 printf("the subranges from the middle value to the highest value is %d to %d", a[5], a[10])5 + & & = a ~ w > Pag, S1 4 Rell) 1805032 Problem 28. Find and print all the prime numbers from 2 to 1000. Program: #include void main() { int 4, J, 6 printf ("All prime numbers between 2 to 100 are:\n"); for(in2; ice1¢00; i++) { =a For(J=25 je=i/23 j++) t if (i%j==0) { C=O break; c==1) O print#("%d, ", i); = Problem 29. Find the roots of the equation’ -(given values of a, b, c). ax? + bx + ¢=0. Program: #include #includecmath. h> void main() { float x1, x2, a, b, ¢, D, real, imag; printf ("Enter values of a, b, ¢:\n"); scanf("SF %F ZF", Ba, &b, &c); Debtb-4*a*c3 if(D==0) { xd=x2=-b/ (2a); printf ("x1=x2=%g", x1); else if(D>9) t x1=(-besqrt(D))/(2*a)5 b-sqrt(D))/(2*a); Oo void main() { int n, revs0, t5 printf ("Enter a four digit integer:\n"); as Kd", &n); R printf (“reverse of digits= %d", rev); Problem 31. Given 10 values, find and print the two values with the least difference. Program: #include #include int least_diff(int arr[], int n); void main() t int arr[10], x; printf ("Enter ten values: for (x = 03 x < 105 x++) scanf("%d", Sarr[x]); printf ("Least difference is %d", least_diff(arr, 10)); + & ce & a & Oo #includeggmath.h> Q int paige _diff(int arr[], int n); oO volt main() SY int arr[19], x; printf ("Enter ten value: for (x = @3 x < 10; x++) scanf("%d", &arr[x]);5 printf ("biggest difference is %d", biggest_diff(arr, 10)); + int biggest_diff(int arr[], int n) { int 4, j, p,q, diff = arr(o]; for (i = 0; i < nj ist) for (j= itt; 5 ¢n5 5+) if (abs(arr[i] - are[j]) > diff) { éiff = abs(arr[i] - arr[4]); p = arr[i}; q = arr[j]; } printf("\nThe two values with the biggest difference: %4 %d\n", p, q)i return diff; + & ce & a & oO ~~ Pag& 17 Rell) 1805032 Problem 33. Given 10 values, print the values, which are less than the mean of all ten values. Program: #include void main() { int 4, a[100], s=93 float mean; printf ("ENTER 1@ INTEGER NUMBERS: \n")5 for(i=0; ic; i++) scanf("%é", @afi])5 ice; i++) sestali]; mean=(float)s/10; for(i=0; ici@; i++) { for(: if (mean>a[i]) printf("x3d", afi]); RK KR RK Probin 34, Input name and age of each of 10 aia persons and sort the data into and ascend ier of age. > oS ie Ss < Q° #include struct person { int age; char name[25]; b void main() { struct person array[100], t; int 4, 35 printf ("Input name and age of 10 different persons (NAME AGE): \n"); for (1 = 03 1 < 10; i++) scanf("%s Xd", array(i].name, &array[i].age); for (i = 03 i < 10; i++) { for (j { 3 <0 - 15 5+) if (array[j].age > array[j + 1].age) { & ce & a & oO ~~ Pas& 1s Rell) 1805032 t = array[j]; array[j] = array(j + 115 array[j + 1] = t; + + printf("\nThe data in order of ascending age\n"); for (i = 05 i < 10; i++) printf("%s\t%d\n", array[i].name, array[i] age); Problem 35. Input name and age of each of each of 20 different persons and sort the data in order of descending age. Program: #include struct person { inteSaes R R Prim: oe co & ~ “ S S OVoid main() Oo { Q struct person array[100], t; int i, 33 printf("Input name and age of 20 different persons (NAME AGE): \n"); for (i = 0; i < 20; i++) scanf("%s Xd", array[i].name, &array[4].age)s for (i = @; i < 20; i++) { for (j = 6; j < 20 - 1; j++) { if (array[j].age < array[j + 1].age) { + = array(i]s array[j] = array[j + 1]; areay[j +1] = t3 } } } printf("\nThe data in order of descending age\n"); for (i = 05 1 ¢ 20; i++) printf("%s\t%d\n", array[i].name, array[i].age); + & oo & a & Oo #include struct person { int age; char name[25]; b void main() { struct person array[100], t; int 4, 43 printf("Input name and age of 10 different persons (NAME AGE): \n"); for (4 = 05 4 ¢ 105 444) scanf("%s %d", array[i].name, &array[i].age); me 3 1<10; i++) Ld RX oO “.((strcmp("NANNU" , srray{t].nane) es printf("%s\t%d\n", array[ i] -aag 5 array[i].age); ~N ss Problem 37. Find the names of persons with the minimum age difference in Problem- 34. Program: include struct person { int age; char name[25]5 Bb void main() { struct person array[100]; int i, 5, diff, p, a printf ("Input name and age of 10 different persons (NAME AGE): \n"); for (i = 93 i < 10; i++) scanf("%s Xd", Sarray[i].name, &array[i].age); & ce & a & Oo ww Pag 20 Rell) 1805032 diff sarray[0].age; for (i = 0) i < 10 - for (j =i +15 4 < 105 3+) if (abs(array[i].age - array[j].age) < diff) { diff = abs(array[i].age - array[j].age); pais q=35 } printf("\nNames of persons with the minimum age difference: %s (%d), %s (%d)\n" » array[p].nane, array[p].age, array[q].name, array[q].age); printf("Minimum age difference is %d\n", diff); + Problem 38. From a list of 1000 names, five characters each, find how many are ‘ABDUL’. Program: #include Eeeeagpeie void en ) { o ~Nchar s{1¢00] [100]; int i, c=05 3 printf("Enter names: \n"); 9 for(: 1¢1000; i++) gets(s[i]); for(i=0; i<1000; i++) { if((stremp("ABDUL", s[i]))==0) Hts + printf ("Total number of name ‘ABDUL’ is %d", ¢); Problem 39. Given 10,000 alphabetic characters, find the frequency distribution of the characters— ‘ABYC. Program: #include #include void main() { char [1000]; se a2 R on Pag SS 21 Rell) 1805032 int i,a-0, b=@, c=05 printf("Enter 10000 characters: \n"); gets(s); for(is; icstrlen(s); i++) { if(s[i] at) atts else if(s[i] bes else if(s[i} cts else continues 3 printf ("frequency distribution of ‘A’ is %d\n", a); printf ("frequency distribution of ‘B' is %d\n", b); printf ("frequency distribution of 'C' is %d", c); ba Problem 40. Find the biggest value of (- 2x? + 23x +57) Program: #ing Xveaio. h> KR rekin S sf * float max; Ss max=57-23/(4*(-2)); printf("biggest value of (- 2x2 + 23x + 57) is Xf", max); } Problem 48. Create a function to compute the area of a circle and use the function to find the areas of 5 circles with radii given, Arrange to print the result with headings and appropriate editing instructions. include float area_of_circle(float r); main() t float r[100], A; int 4; for(i=0;ic53 i++) { print#("Enter radius of circle %d:\n", i+1)5 scanf("%f", &r[i]); = area_of_circle(r[i]); printf (“Area of circle %d = %g\n",i+t, A); & Page) 22 Rell) 1805032 float area_of_circle(float r) { return (3.1416*r+r); } Problem 49, Create a function to compute the distance between two coordinate points P (x1, y1) and Q (x2, y2). Use the function to compute distances between 5 pairs of coordinate points with the coordinates given. Program: #include #include float distance(float x1,float y1,float x2,float y2); main() { float x1, x2, yl, y2, D3 int 4; for(istsica2; itt) { Rercrenter %d pair of coordinate poi Risen tie csogunaze s\n", 4) cf printf("Enter coordinate of 1st point;An"); SN scant", axt); ~~ ~~ SP seanteoxes, ayy; < Ss 9 printf(“Enter coordinate of @ig-point:\n"); Q scanf("%F", 8x2); scanf("%F", &y2); Dz distance(x1,y1,x2,y2)3 print#("distance between %d pair of coordinate points = %g\n",i, D); Z } float distance(float x1,float y1,float x2,float y2) { float 4; desqrt ((x1-x2) *(x1-x2)+(y1-y2)*(yl-y2))5 return d; Problem 50, Write a program to process Degree Exam results on the computer. Assume four subjects of 100 marks each in the examination, A candidate’s record contains data as follows: > Rollnumber — :R & R oO OS Ne ~ a we we Oo “SN Pasgo2s Rell) 1805032 > Mark in subject 1 : MI > Mark in subject 2: M2 > Mark in subject 3 : M3 v Mark in subject 4 : M4 Rules for result processing are as follows: Pass mark in each subject = 33 Aggregate pass mark = 36% (after passing each sub.) 3rd Divn: less than 45% after passing 2nd Divn: less than 60% and 45% or more after passing each. RSLS ‘1st Divn: more than 6r equal to 60% after passing in each. Arrange to print the result of each passed student with the student’s record containing all relevant input and output data. #inclugefStaio. h> R R x x eat student WL WL int roll; Ss © fi lish; joat englis! 9 float bangla; float math; float chemistry; float sum; int result; float number; % int input(int x) { printf("Enter number of students:\n"); scanF("%d" 8x); return(x) 5 + int main() {int ni; n= input (n); struct student student[n]; & 2 & oO NS Pag) 24 Rell) 1805032 for(i=05icnjitt){ printf("\nEnter your roll: \n"); scanf("Kd" student [i] .rol1); printf ("Enter your math Number: scanf("%F", student [i] math) ; printf ("Enter your english number: \n")5 scanf("Xf" ,@student[i] english); printf ("Enter your bangla nunber scant ("%F" student [i] .bangla) ; printf ("Enter your Chemistry number:\n"); scanf("KF" ,@student [i] .chemistry) ; student[i].sum = student[i].math + student[i].english + student[i].bangla + stud ent[i]. chemistry; student[i].number = (student[i].sum * 0.25); n")5 in") if((student[i].english>=33 && student[i].math>=33 8& student[i].bangla>=33 && st udent[i].chemistry>=33 )){ student[i].result=33; t at 2 QRadent{ a resutte325 & cf ~~ <= s S QP toocsnossenssvy¢ if( student[i].result >= 33 && student[i].number >=36 ){ printf("\nRoll no: %d\n", student[i].roll); printf("Mark in Math: %.2f\n", student[i].math); printf("Mark in english: %.2#\n", student[i].english); printf("Mark in bangla: %.2f\n", student[i].bangla); printf("Mark in chemistry:%.2f\n", student[i].chemistry) 5 if( student[i].number 60.0) {printf("Roll %d has got 1st Division", student[i].roll);} else if( (student[i].number >= 45.0) && (student[i].number < [email protected])) {printf("Roll %d has got 2nd Division", student[i].rol1);} else {printf("Roll %d has got 3rd Division", student[i].rol1);} + Problem 51. Rewrite the program above to include referred result processing. A student is referred in a subject if he failed in that subject only and in other three subjects as well as in the aggregate. & R oO OS ° ~ CO struct student: student{in]s Ss oO ss Pag&p25 Rell) 1805032 #includecstdio.h> struct student{ int roll; float english; float bangla; Float math; float chemistry; int result; int input(int x) printf("Enter number of students: \n"); scanF("%d", 8x); return(x) 5 + int mair ri fe & Sn = input(n); For(indsicnsitt){ printf("\nenter your roll:\n"); scanf( "Xd", @student [i] .roll); printf ("Enter your Math Numbei scanf (“%F",@student [i] .math) ; printf ("Enter your English number: \n")5 scanf ("%f" ,@student[i] english); printf ("Enter your Bangla number: \n")5 scanf("%F" student [i] bangla) ; printf ("Enter your Chemistry number:\n"); scanf("%f",@student [i]. chemistry) 5 if((student[i].english < 33 || student[i].math < 33 || student[i].bangla < 33 || student[i].chemistry < 33 )){ student[i].result = 325 d else{ student[i].result=33; 3 + R R < oO © SY or struct student{ int roll float english; float bangla; float math; float chemistry; Float sum; int result; float number; b int input(int x) { printf ("Enter number of students: \n")5 scanf("%d",&x); return(x) 5 x= “w anit we Oo NS ME-2224-(Assignment) PagP27 9 Rell) 1805032 int main() {int nis FILE *file; file = fopen(“prb52.txt","a"); char p[]={"Roll no: “}; char m[]={"Obtained in Math:"}; char e[]={"Obtained in Englist char b[]={"Obtained in Bangla: char c[]={"Obtained in Chemistry:"}; char one[]={"First Division"}; char two[ ]={"Second Division"}; char three[ ]={"Third Division}; n= input (n); struct student student[n]; For(isasicnsitt){ printf("\nEnter your roll:\n"); scanf("%d" ,astudent[i].rol1); pringf("Enter your math Number:\n")5 Q caF OXF" Astudent[ i] math) ; Oo ref (ERG&T” Yan ‘aigtsh rnbers ny oN scanf("%#" ,@student[ i] .english);

printf("Enter your Chemistry number:\n"); scanf("%f",&student[i].chemistry); student[i].sum = student[i].math + student[i].english + student[i].bangla + stud ent[i]. chemistry; student[i].number = (student[i].sum * 0.25); if((student[i] english>=33 && student[i].math>=33 8% student[i].bangla>=33 && st udent [i] .chemistry>=33 )){ student[i].result=33; 3 else{ student[i].result=32; + + for(is@sicnsitt){ if( student[i].result >= 33 && student[i].number >=36 ){ fprintf(file,"\n %s Xd", r ,student[i].roll); fprintf(file,"\n %s %.2#", m, student[i].math); & “ ~ ~~ ~~ Oo Re Pac& 28 Rell) 1805032 fprintf(file,"\n %5 %.2#", b, student[i].bangla); fprintf(file,"\n %s %.2f", e, student[i].english); fprintf(file,"\n %s %.2f", ¢, student[i] chemistry); if( student[i].number >= 60.0) {fprintf(File,"\nXs",one) ;} else if( (student[i].number >= 45.0) && (student[i].number < 69.0) {fpnint#(File, "\nks" two) 5} else {fprint#( File, "\n%s" three) 3} + + fclose(File); Problem 53. Create all relevant files on the disk for problem ~ 51 and process therefrom, Program: Hncludggyio. > x x strc student oO Nit rol; ~ float english; Ss float bangla; 9 float math; float chemistry; int result; b int input(int x) printf ("Enter number of students: \n")5 scanF("%d" ,&x) 5 return(x); int main() FILE *file; int ni; file = fopen(“prbs3.txt","a"); char m[] = {"\nFailed in Math}; char b[] = {"\nFailed in Bangla"}; & ce & a & or Re Pag 29 Rell) 1805032 char e[] = {"\nFailed in English"}; char c{] = {"\nFailed in Chenistry"}; char r[] = {"\n\n Report for roll: "}; n = input(n); struct student student[n]; For(isosicnsit+){ printf("\nEnter your roll:\n"); scanf("Xd" student [i] .rol); printf ("Enter your Math Number:\n")5 scanf("Kf" ,@student [i] .math) ; printf ("Enter your English number: \n"); scanf("%F",&student[i].english) ; printf ("Enter your Bangla nunber scanf ("%F" ,@student [i] bangla); printf ("Enter your Chemistry number:\n"); scanF("%F" ,&student[i] chemistry) ; "95 if((student[i].english < 33 || student[i].math < 33 || student[i].bangla < 33 || student[i] chemistry < 33 )){ ident[i].result = 32; a & & else{ ~~ student [i].result=33; CY For (i=Osicnsitt){ if(student[i].result == 32){ fprintf (file, "%s %d",r, student[i].rol1); if(student[i].math < 33){ fprintf(file, "Xs" , m); + if(student[i] english < 33){ fprintf(file, "Xs" , e); > if(student[i] bangla < 33){ fprintf(file, "Xs" , b); + if(student[i].ch fprintf (File, y dstry < 33){ ws" 5 ¢)3 t + & “ ~ ~~ ~~ anit we we Oo ww Pas& 30 Rell) 1805032 fclose(file); + Problem 54, Create a pay roll input file on disk with each record containing the data: Identification number : ID Basic salary : B Allowances : A vvvyv Deductions : D Create necessary files on disk and process to find PF (10%), gross salary and the net salary. Arrange to save the output file. Program: #includecstdio.h> ae yal & basic; oO Sloat allowance; “ NS < float deductions; Ss float pfs 9 float gross; Float net Bz int input(int x) { printf ("Enter number of employees: \n"); scant ("%d" 8x) 5 return(x); + int main() {int ni; n= input(n); struct student student[n]; FILE *File; file = fopen(“prbs4.txt","a"); char d[]={"ID: "}5 & 2 & Oo “NS Pag O31 Rell) 1805032 ={"Net Salary: PF: *}5 for(i=ojicnjit+){ printf("\nEnter your 1D: scanf("Xd" ,astudent[1].id); printf("Enter your Basic Salary:\n"); scanf("%F" ,astudent[i].basic); printf ("Enter your Allowances: \n"); scanf("%F" ,@student [i] .allowance) ; printf ("Enter your Deductions: \n"); scanf ("%F" ,@student [i] .deductions) ; student[i].pf = student[i].basic * .1 ; student[i].gross = student[i].basic + student[i].allowance; student[i].net = student[i].gross - student[i].deductions - student[i].pf + Fort gypssension)( R SS ntf(file, "\n\n%s %d" ,d, student (G}id) 5 Nfprintf(file, “\n%s %f "jp, student[h}. pf); ss <> fprintf(file, "\n%s %f " jg, stud J.gross); Ss SY fprintf(file, "\n%s Xf " ns, int[i].net); Q 3 fclose(file); Problem 55. Use the output file in problem 56 to print the payroll records of persons drawing a gross salary of TK 7,000/ - or above. Program: #include struct student{ int id; float basic; float allowance; float deductions; float pf; float gross; & NS w =~ ~~ ek we oO Pd Pag 32 Rell) 1805032 float nets Bb int input(int x) { printf("Enter number of employees:\n"); scanf("%d" ,8x)3 return(x) ; + int main() {int nis n= input(n); struct student student[n]; FILE “file; file = fopen("prbs4.txt","a"); char d[]={"1D: "}; "Net Salary: PF: “ys Forcinosdensiee){ print #("\nEnter your 1D:\n"); SY 9 scanf("%d" ,Astudent[] id) ; printf ("Enter your Basic Salary:\n")5 scanf("%f" , &student [i] .basic); printf ("Enter your Allowances: \n"); scanf(°%F" , student [i] allowance); printf("Enter your Deductions: \n"); scanf("%F" , student [i] deductions) ; student[i].pf = student[i].basic * .1 ; student[i].gross = student[i].basic + student[i].allowance; student[i].net = student[i].gross - student[i].deductions - student[i].pf ; } for(i=05d= 7000){ fprintf(file, "\n\n%s %d" jd, student[i].id); fprintf(file, "\n%s Xf " ,p, student[i].pf); fprintf(file, "\nks %f " ,g, student[i].gross); fprintf(file, "\nks %f " ns, student[i].net); t & “ ~ ~~ ~~ anit we we fclose(file) Oo uct student{ int id; float basic; float allowance; float deductions; float pf; float gross; fot & J i ~~ input(int x) < oO \n")5 printf ("Enter number of employe scanF("%d" 8x); return(x); main() int n,ij n= input (n); struct student student[n]; FILE “File; file = fopen(“prbs6.txt","a"); char d[]={"ID: "}3 char g[]={"Gross Salary: char ns[J={"Net Salary: char p[]={"PF : "}3 int count= 0; 3 char cnt[] = {"Number of persons having salary between intervals 1-1000: "}; oO ~~ Pag& 34 Rell) 1805032 printf("\nEnter your scanf("Xd" ,astudent[i].id) 5 printf ("Enter your Basic Salary:\n"); scanf("KF" ,astudent[1].basic); printf ("Enter your Allowances: \n"); scanf("%f" , @student [i] allowance) ; printf ("Enter your Deductions: \n"); scanf("%f" ,@student [i] .deductions) ; student[i].pf = student[i].basic * .1 ; student[i].gross = student[i].basic + student[i].allowance; student[i].net = student[i].gross - student[i].deductions - student[i].pf 5 3 for (is05icnsi+t){ if(student[i].net <= 1000){ count = count + 1; fprintf(file, "\n\n%s %d "jd, student[i].id); fprintf(file, "\n%s %f " ,p, student[i].pf); fprintf(file, "\nts %f " ,g, student[i].gross); fprintf(file, "\n%s %f " ,ns, student[i].nei oO & & oO oO sSfprintf(file, “\n\n\n %s xd", cts ean); } & Fetose(Fite); SY oe ao ~ x

You might also like