Demo of Solution ANSI C(update version)

24
Solution 1 Third Edition Syed Ashik Mahmud 6 th Semester,CSE Patuakhali Science and Technology University Cell:+8801914137796 Md. Abdul Kadir Razu 2 nd Semester,CSE Patuakhali Science and Technology University Cell:+8801911683706 It is an update of demo version of Book of ANSI C Balagurusamy(3 rd Edition) containing Ten chapters. If you need full version then you need to pay for it. Printed version also is got in earlier. Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

description

It is the update of its previous version but to get it full version call me at +8801914137796

Transcript of Demo of Solution ANSI C(update version)

Page 1: Demo of Solution ANSI C(update version)

Solution 1

Third Edition

Syed Ashik Mahmud

6th Semester,CSE Patuakhali Science and Technology University

Cell:+8801914137796

Md. Abdul Kadir Razu 2nd Semester,CSE

Patuakhali Science and Technology University Cell:+8801911683706

It is an update of demo version of Book of ANSI C Balagurusamy(3rd Edition) containing Ten chapters. If you need full version then you need to pay for it. Printed version also is got in earlier.

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 2: Demo of Solution ANSI C(update version)

Solution 2

To our loving parents and Honorable Course Teachers of CSE in PSTU and also our beloved who always inspires us to do something this.

Both these two boys are very curious about programming and the first knowledge gained by this book. For this they are decided to write this solution of this book for those who are novice but very interested in C programming. These two guys are also thankful to E Balagurusamy to give the students such kind of excellent book. So guys lets enjoy with this solution and develop your skill in C programming. Thankful to coders members Rezoan, Mahmud, Bappa, Uzzal, Monir who helps us with their skill. It is our first edition. So there are many wrong or weak logic of program to develop it ur comment is always hoped by us. -----Ashik & Razu Any problem mail or call us at the emergency: +8801914137796

Ashik Razu

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 3: Demo of Solution ANSI C(update version)

Solution 3

Chapter-1

1.1 Same as 1.2

1.2 main() { clrscr(); printf("\n|=================================================|"); printf("\n|Syed Ashik Mahmud. |"); printf("\n|PATUAKHALI SCIENCE AND TECHNOLOGY UNIVERSITY. |"); printf("\n306 West|Sher-E-Bangla hall. |"); printf("\n|_________________________________________________|"); getch(); }

1.3 main() { int i,j,k; clrscr(); printf("\nEnter the number of stars you want: "); scanf("%d",&k); for(i=1;i<=k;i++) { for(j=i;j>=1;j--) { printf(" *"); } printf("\n\n"); } getch(); } 1.4 main() { clrscr(); printf(" _____________ _____________ \n"); printf("| | | |\n"); printf("| | >>---------> | |\n"); printf("|_____________| |_____________|\n"); getch(); } Copy it and paste to notepad. I use it ASCII values of characters which you get at page 459 of this book.

It’s picture is given below:

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 4: Demo of Solution ANSI C(update version)

Solution 4

1.5 #include<math.h> #define pi 3.14 main() { int w; float q; clrscr(); q=pi*(w*w); scanf("%d",&w); printf("%d",w); printf("%d",q); getch(); }

1.6 main() { int i,c,num; clrscr(); printf("\n\n"); for(i=1;i<=10;i++) { c=num*i; printf("%d*%d=%d\n",num,i,c); } getch(); }

1.7 main() { int a,b,x,y; clrscr(); printf("Enter the value of a:"); scanf("%d",&a); printf("Enter the value of b:"); scanf("%d",&b); x=a+b; printf("The value of x:"); printf("%d",x); y=a-b; printf("\nThe value of y:"); printf("%d",y); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 5: Demo of Solution ANSI C(update version)

Solution 5

1.8 main() { float a,b,c; float x; clrscr(); printf("enter the value of a:"); scanf("%f",&a); printf("enter the value of b:"); scanf("%f",&b); printf("enter the value of c:"); scanf("%f",&c); x=a/(b-c); printf("the value of x"); printf("%.2f",x); getch(); }

Chapter-2

2.1 main() { float n,i; float sum; sum=0; clrscr(); printf("Enter a value for n: "); scanf("%f",&n); for(i=1;i<=n;i++) sum=sum+i*i; printf("%.2f",sum); getch(); }

2.2 #define TK 100 main() { float tk,paisa; clrscr(); scanf("%f",&tk); paisa=TK*tk; printf("paisa=%.0f",paisa); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 6: Demo of Solution ANSI C(update version)

Solution 6

2.3 #define N 100 main() { int a; clrscr(); for(a=1;a<=100;a++) { if(a%2==0) printf(" %d",a); } getch(); } 2.4 main() { float a,b,c; clrscr(); scanf("%f %f",&a,&b); c=a/b; printf("%.3f/%.3f=%.2f",a,b,c); getch(); } 2.5 main() { float rice,sugar; clrscr(); scanf("%f %f",&rice,&sugar); printf("******LIST OF ITEMS******\n"); printf("Item Price\n"); printf("Rice Rs%.2f\n",rice); printf("Sugar Rs%.2f\n",sugar); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 7: Demo of Solution ANSI C(update version)

Solution 7

Chapter-3

3.1 main() { int p,q,r,j; clrscr(); p=2; q=3; r=4; j=p; p=q; printf("P: %d ",p); q=r; printf("\nQ: %d ",q); r=j; printf("\nR: %d ",r); getch(); } 3.2 main() { float a; int b; clrscr(); scanf("%f",&a); b=(int)a%10; printf("%d",b); getch(); }

3.3 Same as 3.2. Try it yourself. Not possible call me at +8801914137796. 3.4 main() { int l,w,a,d; clrscr(); scanf(" %d",&l); scanf(" %d",&w); a=l*w; printf(" \nAREA =%d",a); d=2*(l+w); printf("\nPerimeter=%d",d); getch(); }

3.5

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 8: Demo of Solution ANSI C(update version)

Solution 8

main() { int a,b,c,d; clrscr(); scanf("%d",&a); //printf("%d\n",a); b=a%1000; printf("%d\n",b); c=b%100; printf("%d\n",c); d=c%10; printf("%d",d); getch(); }

Dynamic of 3.5 main() { int i=5,j,n; clrscr(); printf("Enter a number: "); scanf("%d",&n); for (i=5;i<=n;i++) { for(j=i;j<=n;j++) { printf("%d",j); } printf("\n"); } getch(); } 3.6 void main() { int d,p,s,y; clrscr(); printf("\nEnter your purchase price : "); scanf("%d",&p); printf("\nEnter your year of service : "); scanf("%d",&y); printf("\nEnter your depreciation : "); scanf("%d",&d); /* Given That : Depreciation,d=(Purchase Price,p - Salvage Value,s)/Year Of Service,y. so,s=p-d*y.*/ s=p-d*y; printf("\nyour Salvage Value is : %d",s); printf("\n"); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 9: Demo of Solution ANSI C(update version)

Solution 9

3.7

Try yourself. It is very easy. Uses ceil and floor function for it. You get it at the page of 72 of this book. 3.8 #include<math.h> main() { float u,a,t,d; clrscr(); printf("Initial velocity u="); scanf("%f",&u); printf("acelaretion a="); scanf("%f",&a); printf("time t="); scanf("%f",&t); d=(u*t)+(a*pow(t,2))/2; printf("the value of s is= %.2f",d); getch(); }

3.9 # include<math.h> main() { float d,h,s,e,t; clrscr(); printf("the value of d="); scanf("%f",&d); printf("the value of s="); scanf("%f",&s); printf("the value of h="); scanf("%f",&h); e=sqrt(2*(d*s)/h); printf("the result is=%f\n",e); t=sqrt(2*(s)/(d*h)); printf ("the result is=%f",t); getch(); } 3.10 #include<math.h> main() { float l=4,r=2,c=0.1,f; clrscr(); printf("for diff. value of c (0.01-0.1), frequency by order:\n\n\a\a\a\a\a\a");

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 10: Demo of Solution ANSI C(update version)

Solution 10

//gotoxy(20,4); for(c=0.01;c<=0.1;c+=0.01) { f=sqrt((1/(l*c))-((1/4)*pow(r/c,2))); printf("\t\t\t\t\t\t\t%.2f\n",f); } getch(); } Alter of 3.10 main() { float c=0.01; for(a=0.01;a<=0.1;a+=0.01) f=sqrt((1/(l*c))-((1/4)*pow(r/c,2))); getch(); }

Chapter-4

4.1 void main() { char name1[15]="WORD PROCESSING"; char name2[15]="WORD"; char name3 [15]="PROCESSING"; clrscr(); printf("OUTPUT OF THE STRINGS\n\n"); printf("%s\n",name1); printf("%.4s\n",name1); printf("%s\n",name3); printf("%.1s.",name2); printf("%.1s.",name3); getch(); } 4.2 void main() { float x,y,p,q,r; clrscr(); scanf("%f%f",&x,&y);

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 11: Demo of Solution ANSI C(update version)

Solution 11

p=(x+y)/(x-y); q=(x+y)/2; r=(x+y)*(x-y); printf("%f\t%f\t%f",p,q,r); getch(); }

4.3 #include<math.h> void main() { float a,b,c,d; int p,q,r,s; clrscr(); scanf("%f%f%f%f",&a,&b,&c,&d); p=floor(a); q=floor(b); r=floor(c); s=floor(d); printf("%d\n",p); printf("%d\n",q); printf("%d\n",r); printf("%d",s); getch(); } 4.4 void main() { float a,b,c,d; int e,f,g,h,i=1; clrscr(); scanf("%f",&a); scanf("%f",&b); scanf("%f",&c); scanf("%f",&d); e=floor(a); f=floor(b); g=floor(c); h=floor(d); while(i<e) { printf("*\t"); i++; } while(i<f) { printf("*\t"); i++; } while(i<g)

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 12: Demo of Solution ANSI C(update version)

Solution 12

{ printf("*\t"); i++; } while(i<h) { printf("*\t"); i++; } getch(); } 4.5 void main() { int a,b,c,d,e,f,g,h; clrscr(); scanf("%d%d",&a,&b); c=b%10; d=b/10; e=(int)d; f=c*a; g=e*a; h=a*b; printf("\t\t\t\t\%d\n",a); printf("\t\t\t*\t%d\n",b); printf("\t\t\t---------------\a\n"); printf("\t%d*%d is\t\t\t%d\n",c,a,f); printf("\t%d*%d is\t\t\t\b%d\n",e,a,g); printf("\t\t\t---------------\n"); printf("\tAdd them\t\t\b%d",h); getch(); }

Chapter-5

5.1 void main() { int a,i; clrscr(); printf("ENTER YOUR NUMBER="); scanf("%d",&a); if(a%2==0) { printf("THE NUMBER IS EVEN"); } else

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 13: Demo of Solution ANSI C(update version)

Solution 13

{ printf("THE NUMBER IS ODD"); } getch(); } 5.2 void main() { int a,sum=0; clrscr(); for(a=100;a<=200;a++) { if(a%7==0) sum=sum+a; }x printf("\n%d",sum); //printf("\n%d",sum); getch(); } 5.3 void main() { int a,b,c,d,x1,x2,m,n; clrscr(); printf("ENTER THE VALUE OF a="); scanf("%d",&a); printf("ENTE THE VALUE OF b="); scanf("%d",&b); printf("ENTER THE VALUE OF c="); scanf("%d",&c); printf("ENTER THE VALUE OF d="); scanf("%d",&d); printf("ENTER THE VALUE OF m="); scanf("%d",&m); printf("ENTER THE VALUE OF n="); scanf("%d",&n); x1= (m*d-b*n)/(a*d-c*b); x2=(n*a-m*c)/(a*d-c*b); if((a*d-c*b!=0)) printf("MATHMATICALLY IT IS NOT DEFINED"); else printf("%d%d",x1,x2); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 14: Demo of Solution ANSI C(update version)

Solution 14

5.4 main() { int count0,count1,count2,count3,count4,count5,count6,count7,i; int number,n; clrscr(); count0=count1=count2=count3=count4=count5=count6=count7=0; printf("Enter the number of marks for student: ") ; scanf("%d",&n); printf("\nEnter the marks for student: ") ; for(i=1;i<=n;i++) { scanf("%d",&number); if(number>80) count0=count0+1; if(number>80) count1=count1+1; if(number>80) count2=count2+1; if(number==40&&number<40) count3=count3+1; if(number>=81&&number<=100) count4=count4+1; if(number>=61&&number<=80) count5=count5+1; if(number>=41&&number<=60) count6=count6+1; if(number>=0&&number<=40) count7=count7+1; } printf("\nGreater than 80=%d",count0) ; printf("\nGreater than 60=%d",count1) ; printf("\nGreater than 40=%d",count2) ; printf("\nObatain 40 or less=%d",count3) ; printf("\nin the range of 81 and 100=%d",count4) ; printf("\nin the range of 61 and 80=%d",count5) ; printf("\nin the range of 41 and 60=%d",count6) ; printf("\nin the range of 0 and 40=%d",count7) ; getch(); } 5.5 void main() { int m,p,c,mpc,mp,md; clrscr(); printf("ENTER THE NUMBER OF MATH="); scanf("%d",&m); printf("ENTER THE NUMBER OF PHYSICS=");

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 15: Demo of Solution ANSI C(update version)

Solution 15

scanf("%d",&p); printf("ENTER THE NUMBER OF CHEMISTRY="); scanf("%d",&c); mpc=m+p+c; mp=m+p; if(m>=60&&p>=50&&c>=40&&mpc>=200&&mp>=150) printf("\nCONGURTULATION!\nYOU CAN APPLY FOR THIS COURSE.\n"); else printf("\nSORRY!\nYOU NEED NOT TO APPLY.\n"); getch(); }

5.6 Try it yourself. Not possible call me at +8801914137796. 5.7 (a) main() { int a=1,i,j;clrscr(); for(i=1;i<=4 ;i++) { for(j=1;j<=i;j++) { printf("%d ",a); a++; } printf("\n"); } getch(); } (b) Try it yourself. Not possible call me at +8801914137796. 5.8 Try it yourself. It is likely 5.4 but in place of if you use switch and in switch you use if. Not possible call me at +8801914137796. 5.9 (a) main() { int x,y; clrscr(); printf("Enter the value for x: "); scanf("%d",&x);

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 16: Demo of Solution ANSI C(update version)

Solution 16

if(x==0) y=0; { if(x>0) y=1; { if(x<0) y=-1; } } printf("Y=%d",y); getch(); }

(b) main() { int x,y; clrscr(); printf("Enter the value for x: "); scanf("%d",&x); if(x==0) y=0; else if(x>0) y=1; else y=-1; printf("Y=%d",y); getch(); } (c) main() { int x,y; clrscr(); printf("Enter the value for x: "); scanf("%d",&x); y=(x!=0)?((x>0)?1:-1):0; printf("\n\nY=%d",y); getch(); }

5.10 #include<math.h> main() { float a,b,c,discriminant,root1,root2; clrscr(); printf("Enter the value for a: "); scanf("%f",&a); printf("\n\nEnter the value for b: "); scanf("%f",&b); printf("\n\nEnter the value for c: ");

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 17: Demo of Solution ANSI C(update version)

Solution 17

scanf("%f",&c); discriminant=b*b-4*a*c; if(discriminant==(b*b)) printf("\n\nThere is only one root"); else if(discriminant<0) printf("\n\nThe roots are imaginary"); else { root1=(-b+sqrt(discriminant))/(2.0*a); root2=(-b-sqrt(discriminant))/(2.0*a); printf("\n\nx1=%f \n\nx2=%f",root1,root2); } getch(); }

Chapter-6

6.1 void main() { int n,j; clrscr(); printf("Enter your no: "); scanf("%d",&n); while(n!=0) { printf("%d",n%10); n=n/10; } getch(); }

6.2 int factorial(int n) { int fact; if(n==1) return(1); else fact=n*factorial(n-1); return(fact); } void main() { int a; clrscr(); printf("Enter a number to know its factorial: "); scanf("%d",&a); printf("\n\nIts factorial is: %d",factorial(a)); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 18: Demo of Solution ANSI C(update version)

Solution 18

6.3 void main() { int a,b,c,n,sum=0; clrscr(); scanf("%d",&n); while(n!=0) { a=n%10; sum=a+sum; n=n/10; } printf("%d",sum); getch(); }

6.4 void main() { int a,b,c,d,i,m; clrscr(); printf("Enter a number: "); scanf("%d",&m); a=1; b=1; printf("\n%d\n%d",a,b); i=2; do { c=a+b; printf("\n%d",c); a=b; b=c; i++; }while(i<=m-1); getch(); }

6.5 Try it yourself. It is same as 6.1 but in place of while you use for. Not possible call me at +8801914137796. 6.6 #include<math.h> main() { int p,n,choice,i; float r,v; clrscr(); printf("How many combination do you want: "); scanf("%d",&choice); for(i=1;i<=choice;i++) {

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 19: Demo of Solution ANSI C(update version)

Solution 19

printf("\nEnter the value for p: "); scanf("%d",&p); printf("\nEnter the value for r: "); scanf("%f",&r); printf("\nEnter the value for n: "); scanf("%d",&n); v=p*(pow((1+r),n)); printf("\nThe value of V: %.2f",v); } getch(); }

6.7 (a) void main() { int i,j,k; clrscr(); { for(i=1;i<=5;i++) { for(j=0;j<i;j++) { printf("%d",i); } printf("\n"); } getch(); }

(b) void main() { int i,j,k; clrscr(); for(i=1;i<=5;i++) { for(j=0;j<i;j++) { printf(" "); } for(j=i;j<=5;j++) { printf("*"); } printf("\n"); } getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 20: Demo of Solution ANSI C(update version)

Solution 20

6.8 main() { int age,i,choice,num=0; printf("Enter the number of persion: ");/* you can choice 100 person or less as you wish */ scanf("%d",&choice); printf("\n\n Enter the people age: "); for(i=1;i<=choice;i++) { scanf("%d",&age); if(age>=50&&age<=60) { num++; continue; } } printf("\n\nThe number of persion between the age 50 to 60 is: %d",num); getch(); }

6.9 Try it yourself. It is same as 6.1 but in place of while you use for. Not possible call me at +8801914137796. 6.10 Try it yourself. It is quietly same as case studies 4(Page 172). Not possible call me at +8801914137796. 6.11 #include <stdio.h> main() { int a,i,c,b[8]; clrscr(); printf("\nEnter a decimal value: "); scanf("%d",&a); c=a; for(i=0;i<=7;i++) { b[i]=c%2; c=c/2; } printf("\nThe value of %d is ",a); for(i=7;i>=0;i--) printf("%d",b[i]); printf(" in binary.\n"); getch(); }

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 21: Demo of Solution ANSI C(update version)

Solution 21

6.12 Try it yourself. It is easy. Not possible mail me at call me at +8801914137796.

6.13 main() { int i,x,n; float s=1,k=1; clrscr(); scanf("%d",&n); for(i=1;i<=n;i++) { k=k*1/i; s=s+k; } printf("%.2f",s); getch(); }

6.14 Try it yourself. It is easy. Not possible call me at +8801914137796. 6.15 Try it yourself. It is easy. Not possible call me at +8801914137796.

Chapter-7

7.1 It is so easy. Not possible call me at +8801914137796. One thing here the output is shown as y=.75x+.85. So you need to calculate the m and c first. Understand. 7.2 It is not done yet. 7.3 main() { int candidate[5]; int vote[20];

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 22: Demo of Solution ANSI C(update version)

Solution 22

int i,n,sum,sum1,sum2,sum3,sum4,spoilt; clrscr(); sum=0; sum1=0; sum2=0; sum3=0; sum4=0; spoilt=0; printf("Enter the number of voters: "); scanf("%d",&n); printf("\n\nGive your vote according to the candidates(1-5)\n\n"); for(i=1;i<=n;i++) { scanf("%d",&vote[i]); if(vote[i]==1) { sum=sum+1; } else if(vote[i]==2) { sum1=sum1+1; } else if(vote[i]==3) { sum2=sum2+1; } else if(vote[i]==4) { sum3=sum3+1; } else if(vote[i]==5) { sum4=sum4+1; } else { spoilt=spoilt+1; } } printf("\n\ncandidate 1 get:%d ",sum); printf("\n\ncandidate 2 get:%d ",sum1); printf("\n\ncandidate 3 get:%d ",sum2); printf("\n\ncandidate 4 get:%d ",sum3); printf("\n\ncandidate 5 get:%d ",sum4); printf("\n\nSpoilt votese are: %d ",spoilt); getch(); }

7.4 void main() { int a[10][10],i,j; clrscr(); for(i=0;i<=10;i++) for(j=0;j<=10;j++) a[i][j]=0; for(i=1;i<=10;i++) for(j=1;j<=10;j++)

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 23: Demo of Solution ANSI C(update version)

Solution 23

if(i==1&&j==1) a[i][j]=1; else a[i][j]=a[i-1][j-1]+a[i-1][j]; for(i=1;i<=10;i++) { for(j=1;j<=10;j++) { if(a[i][j]!=0) printf("%d",a[i][j]); printf("\t"); } } printf("\n"); getch(); }

7.5 Here I do this program only for five students and three subjects and also give marks for them. You can easily modify the program by changing the contribution. Not possible call me at +8801914137796

This is an update of demo version. To get all the full versions call me at +8801914137796. But it is written for business purpose so you need to pay a few to get this full version. It is a give and take process. Call me then I discuss about the conditions. I want good friends. Thanks--- Ashik 306West, Sher-E-Bangla Hall. Patuakhali Science and Technology University. Dumki-8602,Patuakhali. Cell: +8801914137796.

All copyright is reserved by:

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.

Page 24: Demo of Solution ANSI C(update version)

Solution 24

Generated by Foxit PDF Creator © Foxit Softwarehttp://www.foxitsoftware.com For evaluation only.