SlideShare a Scribd company logo
1 of 49
Download to read offline
1
2 
Special thanks to: 1. Safiqul Islam sir 2. Saddam 3. Arun 4. Oli 5. Nazmul 6. Basri 7. Naser 8. Rashed 9. Suzabat Vai 10. My dear Google & 11. Others websites 
“It’s hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free.” - Steve McConnell
3 
Chapter 1 1.1 //Program about mailing address 1.1 #include<stdio.h> void main() { printf("Name: Md. Shariful Haque Robin"); printf("nDoor No: 7, Street no: 10"); printf("nCity: Uttara 10 no. sector, Pin code: 1230"); } 1.2 //Program about mailing address With Border line 1.2 #include<stdio.h> void main() { printf("||===========================================||"); printf("n||Name: Md. Shariful Haque Robin ||"); printf("n||Door No: 7, Street no: 10 ||"); printf("n||City: Uttara 10 no. sector, Pin code: 1230 ||"); printf("n||===========================================||"); } 1.3 //print the pattern #include<stdio.h> void main() { printf("*n* *n* * *n* * * *"); } “When you don't create things, you become defined by your tastes rather than ability. Your tastes only narrow & exclude people. So create.” ― Why the Lucky Stiff
4 
1.4 //print the figure 1.4 #include<stdio.h> void main() { printf("|----------| |----------|"); printf("n| | | |"); printf("n| | >>------>> | |"); printf("n| | | |"); printf("n| | | |"); printf("n|----------| |----------|"); } 1.5 //calculate area of a circle #include <stdio.h> #define PI 3.14 void main() { int r; float a; scanf("%d",&r); a=PI*(r*r); printf("Ans is: %f",a); } 1.6 //Multiplication table #include <stdio.h> void main() { printf("5x1=1n5x2=10n5x3=15n5x4=20n5x5=25n5x6=30n5x7=35n5x8=40n5x9=45n5x10=50"); } “Talk is cheap. Show me the code.” ― Linus Torvalds
5 
1.7 //sum and difference 1.7 #include<stdio.h> void main() { int a,b; a=20+10; b=20-10; printf("20+10= %d",a); printf("n20-10= %d",b); } 1.8 //Division 1.8 #include<stdio.h> void main() { int a,b,c; float x; scanf("%d%d%d",&a,&b,&c); x=a/(b-c); printf("Ans is: %f",x); } 1.9(a) //c to f 1.9 #include <stdio.h> void main () { float C, F; scanf ("%f", &F); C= 5*(F-32) /9; printf ("The temparature in Celcius is : %f", C); }
6 
1.9(b) //Relation Between C and F 1.9 #include <stdio.h> void main () { float C, F; scanf ("%f", &C); F= ((9*C)/5)+32; printf ("The temparature in Fahrenheit is : %2f", F); } 1.10 //Area of Triangle #include <stdio.h> #include <math.h> void main() { int S,a,b,c; float A; scanf("%d%d%d",&a,&b,&c); S=(a+b+c)/2; A=sqrt(S*(S-a)*(S-b)*(S-c)); printf("Ans is: %f",A); } 1.11 //Distance Between Two point #include <stdio.h> #include <math.h> void main() { int x1,x2,y1,y2; float D; scanf("%d%d%d%d",&x1,&x2,&y1,&y2); D=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); printf("Ans is: %f",D);}
7 
1.12 //Area And Perimeter 1.12 #include <stdio.h> #include <math.h> void main() { float R,C,A; R=sqrt(((4-0)*(4-0))+((5-0)*(5-0))); C=2*3.14*R; printf("Perimeter is: %f",C); A=3.14*R*R; printf("nArea is: %f",A); } 1.13 //Area 1.13 #include <stdio.h> #include <math.h> void main() { float R,A; R=(sqrt(((5-2)*(5-2))+((6-2)*(6-2))))/2; A=3.14*R*R; printf("nArea is: %f",A); } 1.14 //1.14 display equation #include<stdio.h> void main() { int a,b,c; a=5;
8 
b=8; c=18; printf("%dx+%dy=%d",a,b,c); } 1.15 //1.15 simple calculator #include<stdio.h> void main() { int a,b,sum,Difference,Product; float Division; printf("Enter a & b value: "); scanf("%d%d",&a,&b); printf("nX= %d y=%d",a,b); sum=a+b; Difference=a-b; printf("nsum= %d Difference= %d",sum,Difference); Product=a*b; Division=a/b; printf("nProduct= %d Division= %.2f",Product,Division); }
9 
Chapter 2 2.1 //2.1:determine and print harmonic series #include<stdio.h> main() { float n,sum; n=5; //consider given n value is 5 sum=1+(1/2)+(1/3)+(1/4)+(1/n); printf("Ans is: %.3f",sum); } 2.2 //2.2: convated taka in decimal from to paise #include<stdio.h> main() { int paise; float price; printf("Enter your price: "); scanf("%f",&price); paise=price*100;//we know that taka X 100 = paise printf("n%d Paise",paise); } 2.3 //2.3: find all even number 1 to 100 #include<stdio.h> void main() { int i=0; for(i=2; i<=100; i=i+2) { printf("t%d",i);} }
10 
2.4 //2.4 #include<stdio.h> void main() { float num1,num2,div; printf("Enter your 1st number: "); scanf("%f",&num1); printf("nEnter your 2nd number: "); scanf("%f",&num2); div=num1/num2; printf("nnum1=%f, num2=%f, division=%f",num1,num2,div); } 2.5 //2.5 #include<stdio.h> void main() { float rp,sp;//Here sp=suger price & rp=rice price scanf("%f%f",&rp,&sp); printf("n*** LIST OF ITEMS ***"); printf("nItem Price"); printf("nRice Rs %.2f",rp); printf("nSuger Rs %.2f",sp); } 2.6 //2.6 #include<stdio.h> void main() { int a,b,c; printf("n Input negative number= "); scanf("%d",&a);
11 
printf("n Input positive number= "); scanf("%d",&b); printf("n Set= "); if(a<=0) { for(c=a;c<=b;c=c+1) printf("t%d",c); } } 2.7 //2.7: #include<stdio.h> void main() { int x,y; short int z; printf("Enter x & y valuesn"); scanf("%d%d",&x,&y); z=x+y; printf("x=%d, y=%d, z=%d",x,y,z); } 2.8 //2.8: #include<stdio.h> void main() { float x,y; int z; printf("Enter two values:n"); scanf("%f%f",&x,&y); z=x+y; printf("x=%.3f,y=%.3f, z=%d",x,y,z); }
12 
Chapter 3 3.1 #include<stdio.h> void main() { int x,y,z,Temp; printf("Enter Three Valuesn"); scanf("%d%d%d",&x,&y,&z); Temp=x; x=y; y=z; z=Temp; printf(" x= %d n y= %d n z= %d",x,y,z); } 3.2 #include<stdio.h> void main() { float x; int y,z; printf("Enter floating point number : x= "); scanf("%f",&x); y=x; z=y%10; printf(" nThe Right-most digit of the integral part of the number %f is %d",x,z); } 3.3 #include<stdio.h> void main() { float x; int y,z;
13 
printf("Enter floating point number : x= "); scanf("%f",&x); y=x; z=y%100; printf(" nThe two Right-most digit of the integral part of the number %f is %d",x,z); } 3.4 #include<stdio.h> void main() { int Len,Wid,Area,Peri; printf("Enter the length of the rectangle :n"); scanf("%d",&Len); printf("Enter width of the rectangle :n"); scanf("%d",&Wid); Peri= 2*(Len+Wid); Area= Len*Wid; printf("The perimeter of the rectangle is =%d n",Peri); printf("The area of the rectangle is =%d n",Area); } 3.5 #include<stdio.h> void main() { int x,a,b,c; printf("Enter a four digit number: "); scanf("%d",&x); a=x%1000; b=a%100; c=b%10; printf("%dn",x); printf("%dn",a); printf("%dn",b);
14 
printf("%dn",c); } 3.6 #include<stdio.h> void main() { float Dep,Year_Ser,Pur_Price,Sal_Price; printf("Enter Deperaciation, Year of Service, Purchase pricen"); scanf("%f%f%f",&Dep,&Year_Ser,&Pur_Price); Sal_Price = Pur_Price-(Dep*Year_Ser); printf("The salvage value of an item = %f ",Sal_Price); } 3.7 #include<stdio.h> void main() { int SmallNo,LargeNo; float RealNo; printf("Enter the real no."); scanf("%f",& RealNo); SmallNo=RealNo; LargeNo=RealNo; printf("Smallest integer not "); printf("The given no. "); printf("Largest integer not n"); printf("less than the number "); printf(" greater than the no.n"); printf("%d ", SmallNo); printf("%f ", RealNo); printf("%d ", LargeNo); }
15 
3.8 #include<stdio.h> void main() { int u,t,a; float Dis; printf("Enter the value of u,a and tn"); scanf("%d %d %d",&u,&a,&t); Dis=(u*t)+(a*(t*t))/2; printf("The distance is : %f n",Dis); } 3.9 #include<stdio.h> #include<math.h> void main() { float Dr,Sc,Hc; float TBO,EOQ; printf("Enter Demand Rate n"); scanf("%fn",&Dr); printf("Enter Setup Cost n"); scanf("%fn",&Sc); printf("Enter Holding Cost n"); scanf("%fn",&Hc); EOQ=sqrt((2*Dr*Sc)/Hc); TBO=sqrt((2*Sc)/(Dr*Hc)); printf("The Economic Order Quantity is : %fn",EOQ); printf("The time Between Order is : %f",TBO); }
16 
3.10 #include<stdio.h> #include<math.h> void main() { float L,R,C; float Freq,Temp1,Temp2; printf("Enter Inductance, Resistance, Capacitannce n"); scanf("%f %f %f",&L,&R,&C); Temp1= (1/(L*C)); Temp2= ((R*R)/(4*C*C)); Freq= sqrt(Temp1-Temp2); printf("The Frequency is : %fn",Freq); } 3.11 #include<stdio.h> void main() { int Num,Sum,Sum1,Sum2,Sum3,Sum4; Sum1=Sum2=Sum3=Sum4=0; Sum=0; printf("Enter a Four Digits Numbern",&Num); scanf("%d",&Num); Sum1=Num%10; Num=Num/10; Sum2=Num%10; Num=Num/10; Sum3=Num%10; Num=Num/10; Sum4=Num%10; Num=Num/10; Sum=Sum1+Sum2+Sum3+Sum4; printf("nSum of Digits are :-- %dn",Sum);}
17 
3.12 #include<stdio.h> void main() { printf("Size of Integer Data Type :-- %d n",sizeof(int)); printf("Size of Character Data Type :-- %d n",sizeof(char)); printf("Size of Float Data Type :-- %d n",sizeof(float)); printf("Size of Double Data Type :-- %d n",sizeof(double)); } 3.13 #include<stdio.h> void main() { int x,y,z; printf("Enter Three Numbers:--n"); scanf("%d %d %d",&x,&y,&z); ((x>y)&&(x>z))?printf("Largest is x :-- %d",x):((y>x)&&(y>z))?printf("Largest is y :--%d",y):printf("Largest is z :-- %d",z); } 3.14 #include<stdio.h> void main() { int m,n,x; printf("Enter Two Numbers:--n"); scanf("%d %d",&m,&n); x=m%n; (x==0)?printf("m is multiple of nn"):printf("m is not multiple of nn"); }
18 
3.16 #include<stdio.h> void main() { float Cus1,Cus2,Bill1,Bill2; printf("Enter Numbers of Call of Customer 1:--n"); scanf("%f",&Cus1); printf("Enter Numbers of Call of Customer 2:--n"); scanf("%f",&Cus2); Cus1<=100?Bill1=250:Bill1=(250+Cus1*1.25); Cus2<=100?Bill2=250:Bill2=(250+Cus1*1.25); printf("Mobile Bill of Customer 1:-- %fn",Bill1); printf("Mobile Bill of Customer 2:-- %f",Bill2); }
19 
Chapter 5 5.1(a) #include<stdio.h> #include<stdlib.h> void main() { int x; printf("Enter Your Number: "); scanf("%d",&x); if(x%2==0) { printf("nNUMBER IS EVEN"); exit(0); } printf("nNUMBER IS ODD"); } 5.2(b) #include<stdio.h> void main() { int n; printf("Enter Your Number: "); scanf("%d",&n); if(n%2==0) { printf("nNUMBER IS EVEN"); } else { printf("nNUMBER IS ODD"); } }
20 
5.3 #include<stdio.h> void main() { int a,b,c,d,m,n,R; float x1,x2; printf("Enter values of a,b,c,d,m,nn"); scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&m,&n); R=(a*d)-(c*b); if(R!=0) { x1=(m*d-b*n)/(a*d-c*b); x2=(n*a-m*c)/(a*d-c*b); printf("nThe value of x1=%.3fnThe Value of x2=%.3f",x1,x2); } else { printf("nThe division is not possible"); } } 5.4 #include<stdio.h> void main() { float m; printf("Enter your marks: "); scanf("%f",&m); if(m>80&&m<=100) { printf("nYou have obtained more than 80 markes"); } else if(m>=61&&m<=80) {
21 
printf("nYou have obtained more than 60 markes"); } else if(m>=41&&m<=60) { printf("nYou have obtained more than 40 markes"); } else { printf("nYou have obtained less than 40 markes"); } } 5.5 #include<stdio.h> void main() { float mat,phy,che,total,total_mp; printf("Enter marks of mathmatics: "); scanf("%f",&mat); printf("nEnter marks of physics: "); scanf("%f",&phy); printf("nEnter marks of chemistry: "); scanf("%f",&che); if(mat>=60&&phy>=50&&che>=40&&total>=200) { printf("nThe candidate is eligible for the addmission"); } else { if(total_mp>=150) { printf("nThe candidate is eligible for the addmission"); } else {
22 
printf("nThe candidate is not eligible for the addmission"); } } } 5.7(a) #include <stdio.h> main() { int i,j,n,a=1; printf("Enter n Value: "); scanf("%d",&n); for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { printf("%d ",a); a++; } printf("n"); } return 0; } 5.7(b) #include <stdio.h> main() { int i,j,n,a=1; printf("Enter n Value: "); scanf("%d",&n); for (i = 1; i <= n; i++) {
23 
for (j = 1; j <= i; j++) { printf("%d ",((i+j+1)%2)); a++; } printf("n"); } return 0; } 5.8 #include<stdio.h> #include<math.h> main() { int am,mi,ha,tomi,toha; printf("Enter your ammount:"); scanf ("%d",&am); if (am>0 && am<=100) { mi=(0); ha=((am*5)/100); } else if(am>101 && am<=200) { mi=((am*5)/100); ha=((am*7.5)/100); } else if(am>201 && am<=300) { mi=((am*7.5)/100); ha=((am*10.0)/100); } else if(am>301)
24 
{ mi=((am*10.0)/100); ha=((am*15.0)/100); } printf("Discount Mill cloth=%d",mi); printf("nDiscount Handloon items=%d",ha); tomi=am-mi; toha=am-ha; printf("nTotal Mill cloth=%d",tomi); printf("nTotal Handloon items=%d",toha); } 5.9(a) #include<stdio.h> void main() { int x; printf("Enter x value: "); scanf("%d",&x); if(x>0) { printf("y value is 1 for given x value"); } if(x==0) { printf("y value is 0 for given x value"); } if(x<0) { printf("y value is -1 for given x value"); } }
25 
5.9(c) #include<stdio.h> void main() { int x; printf("Enter x value: "); scanf("%d",&x); if(x>0) { printf("y value is 1 for given x value"); } else if(x==0) { printf("y value is 0 for given x value"); } else { printf("y value is -1 for given x value"); } } 5.9(c) #include<stdio.h> main() { int x,y; printf("Enter value of x: "); scanf("%d",&x); (x>0?(y=1):(x==0)?(y=0):(y=-1)); printf("The value of y for the given value of x=%d is %dn",x,y); }
26 
5.10 #include<stdio.h> #include<math.h> void main() { int a,b,c,d; float x1,x2,x; printf("Enter value of a,b,cn"); scanf("%d%d%d",&a,&b,&c); d=(b*b)-(4*a*c); if(a==0&&b==0) { printf("No Solution"); } else if(a==0) { x=-c/b; printf("There is only one root and x=%.3f",x); } else if(d<0) { printf("There are no real root"); } else { x1=-b+(sqrt(d)/(2*a)); x2=-b-(sqrt(d)/(2*a)); printf("Roots are real"); printf("x1=%.3fnx2=%.3f",x1,x2); } }
27 
5.11 #include<stdio.h> void main() { int bes,hei,hyp,d,e; scanf("%d%d%d",&bes,&hei,&hyp); d=(bes*bes)+(hei*hei); e=hyp*hyp; if(d==e) { printf("It is right angled triangle"); } else { printf("It is ont right angled triangle"); } } 5.12 #include<stdio.h> void main() { int units; char names; float charge; printf("Enter your name: "); scanf("%s",&names); printf("Enter Total unit amount: "); scanf("%d",&units); if(units>=0&&units<=200) charge=100+(units*0.80); else if(units>200&&units<=300) charge=100+(units*0.90);
28 
else charge=(100+units)+(100+units)*.15; printf("Names Unites Chargen"); printf("%s %d %.2f",names,units,charge); } 5.13 #include<stdio.h> void main() { int n,sum=0; for(n=0;n<=100;n++) { if(n%6==0&&n%4!=0) { printf("%d, ",n); sum=sum+n; } } printf("nnSum= %d",sum); } 5.14 #include<stdio.h> Void main() { int n, c = 2; printf("Enter a number to check if it is primen"); scanf("%d",&n);
29 
for ( c = 2 ; c <= n - 1 ; c++ ) { if ( n%c == 0 ) { printf("%d is not prime.n", n); break; } } if ( c == n ) printf("%d is prime.n", n); return 0; }
30 
Chapter 6 6.1 #include <stdio.h> void main() { int n, reverse = 0; printf("Enter a number to reverse: "); scanf("%d",&n); while (n != 0) { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } printf("nReverse of entered number is = %dn", reverse); } 6.1 #include<stdio.h> void main() { int Num,Temp,RevNum,Dig; printf("Enter any Number: "); scanf("%d",&Num); Temp=Num; RevNum=0; while(Temp!=0) { Dig=Temp%10; Temp=Temp/10;
31 
RevNum=(RevNum*10)+Dig; } printf("nRverse of Number %d is %dn",Num,RevNum); } 6.2 #include <stdio.h> void main() { int c, n, fact = 1; printf("Enter a number: "); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d! = %dn", n, fact); } 6.3 #include<stdio.h> void main() { int Num,Temp,Sum,Dig; printf("Enter any Number: "); scanf("%d",&Num); Temp=Num; Sum=0; while(Temp!=0) {
32 
Dig=Temp%10; Temp=Temp/10; Sum=Sum+Dig; } printf("Sum of Number %ld is %dn",Num,Sum); } 6.4 #include<stdio.h> void main() { int n, first = 0, second = 1, next, c; printf("Enter the number of terms: "); scanf("%d",&n); printf("First %d terms of Fibonacci series are :-n",n); for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; first = second; second = next; } printf("%dn",next); } } 6.5
33 
#include<stdio.h> void main() { int a, s; printf("Enter value of a: "); scanf("%d",&a); for(s=0;a>0;a=a/10) { s = s*10; s = s + (a%10); } printf("Reverse number is: %d",s); } 6.6 #include<stdio.h> #include<conio.h> void main() { int P,n; float V,r,temp; clrscr(); printf("Enter Principal Amount:--n"); scanf("%d",&P); printf("For P:-- %dn",P); for(r=0.1;r<=0.15;r+=0.01) { printf("For Rate %fn",r); printf("n V"); for(n=1;n<=5;n++) { printf("%d ",n); temp=pow((1+r),n); V=P*temp;
34 
printf("%f",V); } } printf("nx = %f; n = %d; x to power n = %fn",x,n,y); getch(); } 6.7 #include<stdio.h> void main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); } printf("n"); } } 6.7(b) #include<stdio.h> void main() { int i,j,k; for(i=5;i>=1;i--) { for(k=5;k>i;k--) printf(" ");
35 
for(j=1;j<=i;j++) { printf("*"); } printf("n"); } } 6.8 #include<stdio.h> void main() { int i,age,c=0; for(i=1;i<=100;i++) { printf("Enter the age of the person%d:",i); scanf("%d",&age); if (age>=50 && age<=60) c=c+1; } printf("The number of persons in the age group 50 to 60 are : %d",c); } 6.9 callected from internet #include<conio.h> #include<stdio.h> #include<math.h> void main() { int i; float a,x,y1,y2; a=0.4;
36 
printf(" Y-----> n"); printf("0---------------------------------------n"); for(x=0;x<5;x=x+0.25) { y1=(int) (50*exp(-a*x)+0.5); y2=(int) (50*exp(-a*x*x/2)+0.5); if(y1==y2) { if(x==2.5) printf("X |"); else printf("|"); for(i=1;i<=y1-1;++i) printf(" "); printf("#n"); } else { if(y1>y2) { if(x==2.5) printf("X |"); else printf(" |"); for(i=1;i<y2-1;i++) printf(" "); printf("*"); for(i=1;i<=(y1-y2-1);++i) printf("-"); printf("0n"); continue; } else { if(x==2.5) printf("X |"); else printf(" |"); for(i=1;i<=(y1-1);++i)
37 
printf(" "); printf("0"); for(i=1;i<=(y2-y1-1);++i) printf("-"); printf("*n"); } } printf(" |n"); } } 6.10 #include<stdio.h> #include<math.h> void main() { float Ex,sum,i,j; printf("X"); for(j=0.1;j<=0.5;j+=0.1) printf(" %f",j); printf("n"); for(i=1;i<=5;i++) { printf("%f",i); for(j=0.1;j<=0.5;j+=0.1) { sum=i+j; Ex=exp(sum); printf(" %f",Ex); } printf("n"); } } 6.11
38 
#include<stdio.h> void main() { int Num,Dig,Bin[10],i,Temp,Count; printf("Enter any Number:--n"); scanf("%d",&Num); Temp=Num; Count=0; while(Temp!=0) { Dig=Temp%2; Temp=Temp/2; Bin[Count]=Dig; Count++; } printf("Binary Number of Integer Number %d is n",Num); for(i=(Count-1);i>=0;i--) printf("%d",Bin[i]); } 6.12 #include<stdio.h> void main() { int i,j,k; j=1; for(i=1;i<=3;i++) for(j=1;j<=18;j++) { printf("*"); if(j==18) printf("n"); } for(i=1;i<=3;i++)
39 
for(j=1;j<=4;j++) { printf("*"); if(j==4) printf("n"); } for(i=1;i<=3;i++) for(j=1;j<=18;j++) { printf("*"); if(j==18) printf("n"); } for(i=1;i<=3;i++) { for(k=1;k<=14;k++) printf(" "); for(j=15;j<=18;j++) { printf("*"); if(j==18) printf("n"); } } for(i=1;i<=3;i++) for(j=1;j<=18;j++) { printf("*"); if(j==18) printf("n"); } }
40 
6.16(a) #include<stdio.h> void main() { int j,i; for (i=1;i<=5;i++) { for(j=1;j<=5;j++) printf("S"); printf("n"); } } 6.16(b) #include<stdio.h> void main() { int j,i,k; for (i=1;i<=5;i++) printf("S"); for(j=2;j<=4;j++) { printf("nS S"); } printf("n"); for (i=1;i<=5;i++) printf("S"); }
41 
6.17 #include<stdio.h> #include<math.h> void main() { float y; int x,i; printf("X Sin(X)n"); for(i=0;i<=180;i+=15) { y=sin(x); printf("%d %fn",x,y); } } 6.18 #include<stdio.h> void main() { int i,Count; Count=0; for(i=1;i<=100;i++) { if(i%2!=0 && i%3!=0) { Count=Count+1; printf("%d",i); } printf("%dn",Count); } }
42 
Chapter 9 9.3 #include<stdio.h> #include<math.h> int Fact(int n) { if(n==0) return 1; else return (n*Fact(n-1)); } float Fx(int x) { float Result=0; int i,j,Temp1,Temp2; for(i=1,j=1;i<=5;i+=2,j++) { if(j%2!=0) { Temp1 = pow(x,i); Temp2 = Fact(i); Result += (float) Temp1/Temp2; } else { Temp1 = pow(x,i); Temp2 = Fact(i); Result -= (float) Temp1/Temp2; } } return Result; } void main() { int No; float F;
43 
printf("Enter a Number-->n"); scanf("%d",&No); F = Fx(No); printf("Result--> %f",F); } 9.7 int prime(int x) { int i; for(i=2;i<=x/2;i++) { if(x%i==0) return 0; } return 1; } void main() { int n,c; printf("Enter a Number-->n"); scanf("%d",&n); c = prime(n); if(c==1) printf("nNumber %d is Prime",n); else printf("nNumber %d is Not Prime",n); }
44 
9.10 #include<math.h> #include<stdio.h> int a,b,c; void Read() { printf("Enter three sides of Triangle-->n"); scanf("%d %d %d",&a,&b,&c); } void Area() { double S,Area,Temp; S=(double) (a+b+c)/2; Area=sqrt((S-a)*(S-b)*(S-c)); printf("Area of Triangle:--> %lf",Area); } void Peri() { int P; P=a+b+c; printf("Perimeter of Triangle:--> %d",P); } void main() { int ch; Read(); while(1) { printf("1. Area n2. Perimeter n3. Exitn"); printf("Enter UR Choicen"); scanf("%d",&ch); switch(ch) { case 1: Area(); break;
45 
case 2: Peri(); break; default: break; } } } 9.11 #include<stdio.h> #define MAX 10 int Largest(int a[][MAX],int m,int n) { int Large,i,j; Large=a[0][0]; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(Large<a[i][j]) Large=a[i][j]; } } return Large; } void main() { int A[MAX][MAX]; int L,m,n,i,j; printf("Enter Number of Rowsn"); scanf("%d",&m); printf("Enter Number of Columnsn"); scanf("%d",&n); printf("Enter Elements of Matrix:--n");
46 
for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&A[i][j]); } } printf("Matrix is:--n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",A[i][j]); } } L = Largest(A,m,n); printf("nLargest Element :-- %d",L); } 9.12 #include<stdio.h> #include<conio.h> #define MAX 10 void Multiplication(int a[][MAX],int b[][MAX],int m,int n1) { int c[MAX][MAX],i,j,k; for(i=0;i<m;i++) { for(j=0;j<n1;j++) { c[i][j]=0; for(k=0;k<m;k++) c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } }
47 
printf("Multiplication of Matrices is:--n"); for(i=0;i<m;i++) { for(j=0;j<n1;j++) { printf("%d ",c[i][j]); } printf("n"); } } void main() { int A[MAX][MAX],B[MAX][MAX]; int L,m,n,m1,n1,i,j; clrscr(); printf("Enter Number of Rows & Columns First Matrixn"); scanf("%d %d",&m,&n); printf("Enter Number of Rows & Columns of Second Matrixn"); scanf("%d %d",&m1,&n1); if(m==n1) { printf("Enter Elements of First Matrix:--n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&A[i][j]); } } printf("Enter Elements of Second Matrix:--n"); for(i=0;i<m1;i++) { for(j=0;j<n1;j++) { scanf("%d",&B[i][j]); } } clrscr();
48 
printf("First Matrix is:--n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",A[i][j]); } printf("n"); } printf("Second Matrix is:--n"); for(i=0;i<m1;i++) { for(j=0;j<n1;j++) { printf("%d ",B[i][j]); } printf("n"); } Multiplication(A,B,m); } else printf("Multiplication is not applicablen"); getch(); } “Good code is its own best documentation. As you're about to add a comment, ask yourself, "How can I improve the code so that this comment isn't needed?" Improve the code and then document it to make it even clearer. ” - Steve McConnell “Programming can be fun, so can cryptography; however they should not be combined.” - Kreitzberg and Shneiderman “Copy and paste is a design error.” - David Parnas
49

More Related Content

What's hot

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 

What's hot (20)

Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
C Programming
C ProgrammingC Programming
C Programming
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
C++ file
C++ fileC++ file
C++ file
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
C Programming
C ProgrammingC Programming
C Programming
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 

Viewers also liked (9)

Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
Programming in ansi C by Balaguruswami
Programming in ansi C by BalaguruswamiProgramming in ansi C by Balaguruswami
Programming in ansi C by Balaguruswami
 
How to program with c in persian
How to program with c in persianHow to program with c in persian
How to program with c in persian
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
 
IS740 Chapter 05
IS740 Chapter 05IS740 Chapter 05
IS740 Chapter 05
 
Unit 1 water_technology
Unit 1 water_technologyUnit 1 water_technology
Unit 1 water_technology
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 

Similar to The solution manual of programming in ansi by Robin

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C basics
C basicsC basics
C basics
MSc CST
 

Similar to The solution manual of programming in ansi by Robin (20)

C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C file
C fileC file
C file
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
C basics
C basicsC basics
C basics
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
 
7 functions
7  functions7  functions
7 functions
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
cpract.docx
cpract.docxcpract.docx
cpract.docx
 
Unit2 C
Unit2 C Unit2 C
Unit2 C
 

More from Shariful Haque Robin

More from Shariful Haque Robin (11)

Super-Structural Construction Work of a Six Storied Residential Building.
Super-Structural Construction Work of a Six Storied Residential Building.Super-Structural Construction Work of a Six Storied Residential Building.
Super-Structural Construction Work of a Six Storied Residential Building.
 
Analysis and Design of Structural Components of a Ten Storied RCC Residential...
Analysis and Design of Structural Components of a Ten Storied RCC Residential...Analysis and Design of Structural Components of a Ten Storied RCC Residential...
Analysis and Design of Structural Components of a Ten Storied RCC Residential...
 
Cracking in Reinforced Concrete Flexural Members (by Robin)
Cracking in Reinforced Concrete Flexural Members (by Robin)Cracking in Reinforced Concrete Flexural Members (by Robin)
Cracking in Reinforced Concrete Flexural Members (by Robin)
 
Bangladeshi Rail (by Robin)
Bangladeshi Rail (by Robin)Bangladeshi Rail (by Robin)
Bangladeshi Rail (by Robin)
 
Super-Structural Construction Work of a Six Storied Residential Building
Super-Structural Construction Work of a Six Storied Residential BuildingSuper-Structural Construction Work of a Six Storied Residential Building
Super-Structural Construction Work of a Six Storied Residential Building
 
Construction work of a multi storied residential building
Construction work of a multi storied residential buildingConstruction work of a multi storied residential building
Construction work of a multi storied residential building
 
Earthquake
EarthquakeEarthquake
Earthquake
 
Measures of Dispersion
Measures of DispersionMeasures of Dispersion
Measures of Dispersion
 
Alternative Water Supply Technologies.
Alternative Water Supply  Technologies.Alternative Water Supply  Technologies.
Alternative Water Supply Technologies.
 
LOW VOLTAGE ELECTRIC ELEMENT IS USED IN HIGH VOLTAGE SOURCE
LOW VOLTAGE ELECTRIC ELEMENT IS USED  IN HIGH VOLTAGE SOURCELOW VOLTAGE ELECTRIC ELEMENT IS USED  IN HIGH VOLTAGE SOURCE
LOW VOLTAGE ELECTRIC ELEMENT IS USED IN HIGH VOLTAGE SOURCE
 
Presentation on calculus
Presentation on calculusPresentation on calculus
Presentation on calculus
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Recently uploaded (20)

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 

The solution manual of programming in ansi by Robin

  • 1. 1
  • 2. 2 Special thanks to: 1. Safiqul Islam sir 2. Saddam 3. Arun 4. Oli 5. Nazmul 6. Basri 7. Naser 8. Rashed 9. Suzabat Vai 10. My dear Google & 11. Others websites “It’s hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free.” - Steve McConnell
  • 3. 3 Chapter 1 1.1 //Program about mailing address 1.1 #include<stdio.h> void main() { printf("Name: Md. Shariful Haque Robin"); printf("nDoor No: 7, Street no: 10"); printf("nCity: Uttara 10 no. sector, Pin code: 1230"); } 1.2 //Program about mailing address With Border line 1.2 #include<stdio.h> void main() { printf("||===========================================||"); printf("n||Name: Md. Shariful Haque Robin ||"); printf("n||Door No: 7, Street no: 10 ||"); printf("n||City: Uttara 10 no. sector, Pin code: 1230 ||"); printf("n||===========================================||"); } 1.3 //print the pattern #include<stdio.h> void main() { printf("*n* *n* * *n* * * *"); } “When you don't create things, you become defined by your tastes rather than ability. Your tastes only narrow & exclude people. So create.” ― Why the Lucky Stiff
  • 4. 4 1.4 //print the figure 1.4 #include<stdio.h> void main() { printf("|----------| |----------|"); printf("n| | | |"); printf("n| | >>------>> | |"); printf("n| | | |"); printf("n| | | |"); printf("n|----------| |----------|"); } 1.5 //calculate area of a circle #include <stdio.h> #define PI 3.14 void main() { int r; float a; scanf("%d",&r); a=PI*(r*r); printf("Ans is: %f",a); } 1.6 //Multiplication table #include <stdio.h> void main() { printf("5x1=1n5x2=10n5x3=15n5x4=20n5x5=25n5x6=30n5x7=35n5x8=40n5x9=45n5x10=50"); } “Talk is cheap. Show me the code.” ― Linus Torvalds
  • 5. 5 1.7 //sum and difference 1.7 #include<stdio.h> void main() { int a,b; a=20+10; b=20-10; printf("20+10= %d",a); printf("n20-10= %d",b); } 1.8 //Division 1.8 #include<stdio.h> void main() { int a,b,c; float x; scanf("%d%d%d",&a,&b,&c); x=a/(b-c); printf("Ans is: %f",x); } 1.9(a) //c to f 1.9 #include <stdio.h> void main () { float C, F; scanf ("%f", &F); C= 5*(F-32) /9; printf ("The temparature in Celcius is : %f", C); }
  • 6. 6 1.9(b) //Relation Between C and F 1.9 #include <stdio.h> void main () { float C, F; scanf ("%f", &C); F= ((9*C)/5)+32; printf ("The temparature in Fahrenheit is : %2f", F); } 1.10 //Area of Triangle #include <stdio.h> #include <math.h> void main() { int S,a,b,c; float A; scanf("%d%d%d",&a,&b,&c); S=(a+b+c)/2; A=sqrt(S*(S-a)*(S-b)*(S-c)); printf("Ans is: %f",A); } 1.11 //Distance Between Two point #include <stdio.h> #include <math.h> void main() { int x1,x2,y1,y2; float D; scanf("%d%d%d%d",&x1,&x2,&y1,&y2); D=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); printf("Ans is: %f",D);}
  • 7. 7 1.12 //Area And Perimeter 1.12 #include <stdio.h> #include <math.h> void main() { float R,C,A; R=sqrt(((4-0)*(4-0))+((5-0)*(5-0))); C=2*3.14*R; printf("Perimeter is: %f",C); A=3.14*R*R; printf("nArea is: %f",A); } 1.13 //Area 1.13 #include <stdio.h> #include <math.h> void main() { float R,A; R=(sqrt(((5-2)*(5-2))+((6-2)*(6-2))))/2; A=3.14*R*R; printf("nArea is: %f",A); } 1.14 //1.14 display equation #include<stdio.h> void main() { int a,b,c; a=5;
  • 8. 8 b=8; c=18; printf("%dx+%dy=%d",a,b,c); } 1.15 //1.15 simple calculator #include<stdio.h> void main() { int a,b,sum,Difference,Product; float Division; printf("Enter a & b value: "); scanf("%d%d",&a,&b); printf("nX= %d y=%d",a,b); sum=a+b; Difference=a-b; printf("nsum= %d Difference= %d",sum,Difference); Product=a*b; Division=a/b; printf("nProduct= %d Division= %.2f",Product,Division); }
  • 9. 9 Chapter 2 2.1 //2.1:determine and print harmonic series #include<stdio.h> main() { float n,sum; n=5; //consider given n value is 5 sum=1+(1/2)+(1/3)+(1/4)+(1/n); printf("Ans is: %.3f",sum); } 2.2 //2.2: convated taka in decimal from to paise #include<stdio.h> main() { int paise; float price; printf("Enter your price: "); scanf("%f",&price); paise=price*100;//we know that taka X 100 = paise printf("n%d Paise",paise); } 2.3 //2.3: find all even number 1 to 100 #include<stdio.h> void main() { int i=0; for(i=2; i<=100; i=i+2) { printf("t%d",i);} }
  • 10. 10 2.4 //2.4 #include<stdio.h> void main() { float num1,num2,div; printf("Enter your 1st number: "); scanf("%f",&num1); printf("nEnter your 2nd number: "); scanf("%f",&num2); div=num1/num2; printf("nnum1=%f, num2=%f, division=%f",num1,num2,div); } 2.5 //2.5 #include<stdio.h> void main() { float rp,sp;//Here sp=suger price & rp=rice price scanf("%f%f",&rp,&sp); printf("n*** LIST OF ITEMS ***"); printf("nItem Price"); printf("nRice Rs %.2f",rp); printf("nSuger Rs %.2f",sp); } 2.6 //2.6 #include<stdio.h> void main() { int a,b,c; printf("n Input negative number= "); scanf("%d",&a);
  • 11. 11 printf("n Input positive number= "); scanf("%d",&b); printf("n Set= "); if(a<=0) { for(c=a;c<=b;c=c+1) printf("t%d",c); } } 2.7 //2.7: #include<stdio.h> void main() { int x,y; short int z; printf("Enter x & y valuesn"); scanf("%d%d",&x,&y); z=x+y; printf("x=%d, y=%d, z=%d",x,y,z); } 2.8 //2.8: #include<stdio.h> void main() { float x,y; int z; printf("Enter two values:n"); scanf("%f%f",&x,&y); z=x+y; printf("x=%.3f,y=%.3f, z=%d",x,y,z); }
  • 12. 12 Chapter 3 3.1 #include<stdio.h> void main() { int x,y,z,Temp; printf("Enter Three Valuesn"); scanf("%d%d%d",&x,&y,&z); Temp=x; x=y; y=z; z=Temp; printf(" x= %d n y= %d n z= %d",x,y,z); } 3.2 #include<stdio.h> void main() { float x; int y,z; printf("Enter floating point number : x= "); scanf("%f",&x); y=x; z=y%10; printf(" nThe Right-most digit of the integral part of the number %f is %d",x,z); } 3.3 #include<stdio.h> void main() { float x; int y,z;
  • 13. 13 printf("Enter floating point number : x= "); scanf("%f",&x); y=x; z=y%100; printf(" nThe two Right-most digit of the integral part of the number %f is %d",x,z); } 3.4 #include<stdio.h> void main() { int Len,Wid,Area,Peri; printf("Enter the length of the rectangle :n"); scanf("%d",&Len); printf("Enter width of the rectangle :n"); scanf("%d",&Wid); Peri= 2*(Len+Wid); Area= Len*Wid; printf("The perimeter of the rectangle is =%d n",Peri); printf("The area of the rectangle is =%d n",Area); } 3.5 #include<stdio.h> void main() { int x,a,b,c; printf("Enter a four digit number: "); scanf("%d",&x); a=x%1000; b=a%100; c=b%10; printf("%dn",x); printf("%dn",a); printf("%dn",b);
  • 14. 14 printf("%dn",c); } 3.6 #include<stdio.h> void main() { float Dep,Year_Ser,Pur_Price,Sal_Price; printf("Enter Deperaciation, Year of Service, Purchase pricen"); scanf("%f%f%f",&Dep,&Year_Ser,&Pur_Price); Sal_Price = Pur_Price-(Dep*Year_Ser); printf("The salvage value of an item = %f ",Sal_Price); } 3.7 #include<stdio.h> void main() { int SmallNo,LargeNo; float RealNo; printf("Enter the real no."); scanf("%f",& RealNo); SmallNo=RealNo; LargeNo=RealNo; printf("Smallest integer not "); printf("The given no. "); printf("Largest integer not n"); printf("less than the number "); printf(" greater than the no.n"); printf("%d ", SmallNo); printf("%f ", RealNo); printf("%d ", LargeNo); }
  • 15. 15 3.8 #include<stdio.h> void main() { int u,t,a; float Dis; printf("Enter the value of u,a and tn"); scanf("%d %d %d",&u,&a,&t); Dis=(u*t)+(a*(t*t))/2; printf("The distance is : %f n",Dis); } 3.9 #include<stdio.h> #include<math.h> void main() { float Dr,Sc,Hc; float TBO,EOQ; printf("Enter Demand Rate n"); scanf("%fn",&Dr); printf("Enter Setup Cost n"); scanf("%fn",&Sc); printf("Enter Holding Cost n"); scanf("%fn",&Hc); EOQ=sqrt((2*Dr*Sc)/Hc); TBO=sqrt((2*Sc)/(Dr*Hc)); printf("The Economic Order Quantity is : %fn",EOQ); printf("The time Between Order is : %f",TBO); }
  • 16. 16 3.10 #include<stdio.h> #include<math.h> void main() { float L,R,C; float Freq,Temp1,Temp2; printf("Enter Inductance, Resistance, Capacitannce n"); scanf("%f %f %f",&L,&R,&C); Temp1= (1/(L*C)); Temp2= ((R*R)/(4*C*C)); Freq= sqrt(Temp1-Temp2); printf("The Frequency is : %fn",Freq); } 3.11 #include<stdio.h> void main() { int Num,Sum,Sum1,Sum2,Sum3,Sum4; Sum1=Sum2=Sum3=Sum4=0; Sum=0; printf("Enter a Four Digits Numbern",&Num); scanf("%d",&Num); Sum1=Num%10; Num=Num/10; Sum2=Num%10; Num=Num/10; Sum3=Num%10; Num=Num/10; Sum4=Num%10; Num=Num/10; Sum=Sum1+Sum2+Sum3+Sum4; printf("nSum of Digits are :-- %dn",Sum);}
  • 17. 17 3.12 #include<stdio.h> void main() { printf("Size of Integer Data Type :-- %d n",sizeof(int)); printf("Size of Character Data Type :-- %d n",sizeof(char)); printf("Size of Float Data Type :-- %d n",sizeof(float)); printf("Size of Double Data Type :-- %d n",sizeof(double)); } 3.13 #include<stdio.h> void main() { int x,y,z; printf("Enter Three Numbers:--n"); scanf("%d %d %d",&x,&y,&z); ((x>y)&&(x>z))?printf("Largest is x :-- %d",x):((y>x)&&(y>z))?printf("Largest is y :--%d",y):printf("Largest is z :-- %d",z); } 3.14 #include<stdio.h> void main() { int m,n,x; printf("Enter Two Numbers:--n"); scanf("%d %d",&m,&n); x=m%n; (x==0)?printf("m is multiple of nn"):printf("m is not multiple of nn"); }
  • 18. 18 3.16 #include<stdio.h> void main() { float Cus1,Cus2,Bill1,Bill2; printf("Enter Numbers of Call of Customer 1:--n"); scanf("%f",&Cus1); printf("Enter Numbers of Call of Customer 2:--n"); scanf("%f",&Cus2); Cus1<=100?Bill1=250:Bill1=(250+Cus1*1.25); Cus2<=100?Bill2=250:Bill2=(250+Cus1*1.25); printf("Mobile Bill of Customer 1:-- %fn",Bill1); printf("Mobile Bill of Customer 2:-- %f",Bill2); }
  • 19. 19 Chapter 5 5.1(a) #include<stdio.h> #include<stdlib.h> void main() { int x; printf("Enter Your Number: "); scanf("%d",&x); if(x%2==0) { printf("nNUMBER IS EVEN"); exit(0); } printf("nNUMBER IS ODD"); } 5.2(b) #include<stdio.h> void main() { int n; printf("Enter Your Number: "); scanf("%d",&n); if(n%2==0) { printf("nNUMBER IS EVEN"); } else { printf("nNUMBER IS ODD"); } }
  • 20. 20 5.3 #include<stdio.h> void main() { int a,b,c,d,m,n,R; float x1,x2; printf("Enter values of a,b,c,d,m,nn"); scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&m,&n); R=(a*d)-(c*b); if(R!=0) { x1=(m*d-b*n)/(a*d-c*b); x2=(n*a-m*c)/(a*d-c*b); printf("nThe value of x1=%.3fnThe Value of x2=%.3f",x1,x2); } else { printf("nThe division is not possible"); } } 5.4 #include<stdio.h> void main() { float m; printf("Enter your marks: "); scanf("%f",&m); if(m>80&&m<=100) { printf("nYou have obtained more than 80 markes"); } else if(m>=61&&m<=80) {
  • 21. 21 printf("nYou have obtained more than 60 markes"); } else if(m>=41&&m<=60) { printf("nYou have obtained more than 40 markes"); } else { printf("nYou have obtained less than 40 markes"); } } 5.5 #include<stdio.h> void main() { float mat,phy,che,total,total_mp; printf("Enter marks of mathmatics: "); scanf("%f",&mat); printf("nEnter marks of physics: "); scanf("%f",&phy); printf("nEnter marks of chemistry: "); scanf("%f",&che); if(mat>=60&&phy>=50&&che>=40&&total>=200) { printf("nThe candidate is eligible for the addmission"); } else { if(total_mp>=150) { printf("nThe candidate is eligible for the addmission"); } else {
  • 22. 22 printf("nThe candidate is not eligible for the addmission"); } } } 5.7(a) #include <stdio.h> main() { int i,j,n,a=1; printf("Enter n Value: "); scanf("%d",&n); for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { printf("%d ",a); a++; } printf("n"); } return 0; } 5.7(b) #include <stdio.h> main() { int i,j,n,a=1; printf("Enter n Value: "); scanf("%d",&n); for (i = 1; i <= n; i++) {
  • 23. 23 for (j = 1; j <= i; j++) { printf("%d ",((i+j+1)%2)); a++; } printf("n"); } return 0; } 5.8 #include<stdio.h> #include<math.h> main() { int am,mi,ha,tomi,toha; printf("Enter your ammount:"); scanf ("%d",&am); if (am>0 && am<=100) { mi=(0); ha=((am*5)/100); } else if(am>101 && am<=200) { mi=((am*5)/100); ha=((am*7.5)/100); } else if(am>201 && am<=300) { mi=((am*7.5)/100); ha=((am*10.0)/100); } else if(am>301)
  • 24. 24 { mi=((am*10.0)/100); ha=((am*15.0)/100); } printf("Discount Mill cloth=%d",mi); printf("nDiscount Handloon items=%d",ha); tomi=am-mi; toha=am-ha; printf("nTotal Mill cloth=%d",tomi); printf("nTotal Handloon items=%d",toha); } 5.9(a) #include<stdio.h> void main() { int x; printf("Enter x value: "); scanf("%d",&x); if(x>0) { printf("y value is 1 for given x value"); } if(x==0) { printf("y value is 0 for given x value"); } if(x<0) { printf("y value is -1 for given x value"); } }
  • 25. 25 5.9(c) #include<stdio.h> void main() { int x; printf("Enter x value: "); scanf("%d",&x); if(x>0) { printf("y value is 1 for given x value"); } else if(x==0) { printf("y value is 0 for given x value"); } else { printf("y value is -1 for given x value"); } } 5.9(c) #include<stdio.h> main() { int x,y; printf("Enter value of x: "); scanf("%d",&x); (x>0?(y=1):(x==0)?(y=0):(y=-1)); printf("The value of y for the given value of x=%d is %dn",x,y); }
  • 26. 26 5.10 #include<stdio.h> #include<math.h> void main() { int a,b,c,d; float x1,x2,x; printf("Enter value of a,b,cn"); scanf("%d%d%d",&a,&b,&c); d=(b*b)-(4*a*c); if(a==0&&b==0) { printf("No Solution"); } else if(a==0) { x=-c/b; printf("There is only one root and x=%.3f",x); } else if(d<0) { printf("There are no real root"); } else { x1=-b+(sqrt(d)/(2*a)); x2=-b-(sqrt(d)/(2*a)); printf("Roots are real"); printf("x1=%.3fnx2=%.3f",x1,x2); } }
  • 27. 27 5.11 #include<stdio.h> void main() { int bes,hei,hyp,d,e; scanf("%d%d%d",&bes,&hei,&hyp); d=(bes*bes)+(hei*hei); e=hyp*hyp; if(d==e) { printf("It is right angled triangle"); } else { printf("It is ont right angled triangle"); } } 5.12 #include<stdio.h> void main() { int units; char names; float charge; printf("Enter your name: "); scanf("%s",&names); printf("Enter Total unit amount: "); scanf("%d",&units); if(units>=0&&units<=200) charge=100+(units*0.80); else if(units>200&&units<=300) charge=100+(units*0.90);
  • 28. 28 else charge=(100+units)+(100+units)*.15; printf("Names Unites Chargen"); printf("%s %d %.2f",names,units,charge); } 5.13 #include<stdio.h> void main() { int n,sum=0; for(n=0;n<=100;n++) { if(n%6==0&&n%4!=0) { printf("%d, ",n); sum=sum+n; } } printf("nnSum= %d",sum); } 5.14 #include<stdio.h> Void main() { int n, c = 2; printf("Enter a number to check if it is primen"); scanf("%d",&n);
  • 29. 29 for ( c = 2 ; c <= n - 1 ; c++ ) { if ( n%c == 0 ) { printf("%d is not prime.n", n); break; } } if ( c == n ) printf("%d is prime.n", n); return 0; }
  • 30. 30 Chapter 6 6.1 #include <stdio.h> void main() { int n, reverse = 0; printf("Enter a number to reverse: "); scanf("%d",&n); while (n != 0) { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } printf("nReverse of entered number is = %dn", reverse); } 6.1 #include<stdio.h> void main() { int Num,Temp,RevNum,Dig; printf("Enter any Number: "); scanf("%d",&Num); Temp=Num; RevNum=0; while(Temp!=0) { Dig=Temp%10; Temp=Temp/10;
  • 31. 31 RevNum=(RevNum*10)+Dig; } printf("nRverse of Number %d is %dn",Num,RevNum); } 6.2 #include <stdio.h> void main() { int c, n, fact = 1; printf("Enter a number: "); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d! = %dn", n, fact); } 6.3 #include<stdio.h> void main() { int Num,Temp,Sum,Dig; printf("Enter any Number: "); scanf("%d",&Num); Temp=Num; Sum=0; while(Temp!=0) {
  • 32. 32 Dig=Temp%10; Temp=Temp/10; Sum=Sum+Dig; } printf("Sum of Number %ld is %dn",Num,Sum); } 6.4 #include<stdio.h> void main() { int n, first = 0, second = 1, next, c; printf("Enter the number of terms: "); scanf("%d",&n); printf("First %d terms of Fibonacci series are :-n",n); for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; first = second; second = next; } printf("%dn",next); } } 6.5
  • 33. 33 #include<stdio.h> void main() { int a, s; printf("Enter value of a: "); scanf("%d",&a); for(s=0;a>0;a=a/10) { s = s*10; s = s + (a%10); } printf("Reverse number is: %d",s); } 6.6 #include<stdio.h> #include<conio.h> void main() { int P,n; float V,r,temp; clrscr(); printf("Enter Principal Amount:--n"); scanf("%d",&P); printf("For P:-- %dn",P); for(r=0.1;r<=0.15;r+=0.01) { printf("For Rate %fn",r); printf("n V"); for(n=1;n<=5;n++) { printf("%d ",n); temp=pow((1+r),n); V=P*temp;
  • 34. 34 printf("%f",V); } } printf("nx = %f; n = %d; x to power n = %fn",x,n,y); getch(); } 6.7 #include<stdio.h> void main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); } printf("n"); } } 6.7(b) #include<stdio.h> void main() { int i,j,k; for(i=5;i>=1;i--) { for(k=5;k>i;k--) printf(" ");
  • 35. 35 for(j=1;j<=i;j++) { printf("*"); } printf("n"); } } 6.8 #include<stdio.h> void main() { int i,age,c=0; for(i=1;i<=100;i++) { printf("Enter the age of the person%d:",i); scanf("%d",&age); if (age>=50 && age<=60) c=c+1; } printf("The number of persons in the age group 50 to 60 are : %d",c); } 6.9 callected from internet #include<conio.h> #include<stdio.h> #include<math.h> void main() { int i; float a,x,y1,y2; a=0.4;
  • 36. 36 printf(" Y-----> n"); printf("0---------------------------------------n"); for(x=0;x<5;x=x+0.25) { y1=(int) (50*exp(-a*x)+0.5); y2=(int) (50*exp(-a*x*x/2)+0.5); if(y1==y2) { if(x==2.5) printf("X |"); else printf("|"); for(i=1;i<=y1-1;++i) printf(" "); printf("#n"); } else { if(y1>y2) { if(x==2.5) printf("X |"); else printf(" |"); for(i=1;i<y2-1;i++) printf(" "); printf("*"); for(i=1;i<=(y1-y2-1);++i) printf("-"); printf("0n"); continue; } else { if(x==2.5) printf("X |"); else printf(" |"); for(i=1;i<=(y1-1);++i)
  • 37. 37 printf(" "); printf("0"); for(i=1;i<=(y2-y1-1);++i) printf("-"); printf("*n"); } } printf(" |n"); } } 6.10 #include<stdio.h> #include<math.h> void main() { float Ex,sum,i,j; printf("X"); for(j=0.1;j<=0.5;j+=0.1) printf(" %f",j); printf("n"); for(i=1;i<=5;i++) { printf("%f",i); for(j=0.1;j<=0.5;j+=0.1) { sum=i+j; Ex=exp(sum); printf(" %f",Ex); } printf("n"); } } 6.11
  • 38. 38 #include<stdio.h> void main() { int Num,Dig,Bin[10],i,Temp,Count; printf("Enter any Number:--n"); scanf("%d",&Num); Temp=Num; Count=0; while(Temp!=0) { Dig=Temp%2; Temp=Temp/2; Bin[Count]=Dig; Count++; } printf("Binary Number of Integer Number %d is n",Num); for(i=(Count-1);i>=0;i--) printf("%d",Bin[i]); } 6.12 #include<stdio.h> void main() { int i,j,k; j=1; for(i=1;i<=3;i++) for(j=1;j<=18;j++) { printf("*"); if(j==18) printf("n"); } for(i=1;i<=3;i++)
  • 39. 39 for(j=1;j<=4;j++) { printf("*"); if(j==4) printf("n"); } for(i=1;i<=3;i++) for(j=1;j<=18;j++) { printf("*"); if(j==18) printf("n"); } for(i=1;i<=3;i++) { for(k=1;k<=14;k++) printf(" "); for(j=15;j<=18;j++) { printf("*"); if(j==18) printf("n"); } } for(i=1;i<=3;i++) for(j=1;j<=18;j++) { printf("*"); if(j==18) printf("n"); } }
  • 40. 40 6.16(a) #include<stdio.h> void main() { int j,i; for (i=1;i<=5;i++) { for(j=1;j<=5;j++) printf("S"); printf("n"); } } 6.16(b) #include<stdio.h> void main() { int j,i,k; for (i=1;i<=5;i++) printf("S"); for(j=2;j<=4;j++) { printf("nS S"); } printf("n"); for (i=1;i<=5;i++) printf("S"); }
  • 41. 41 6.17 #include<stdio.h> #include<math.h> void main() { float y; int x,i; printf("X Sin(X)n"); for(i=0;i<=180;i+=15) { y=sin(x); printf("%d %fn",x,y); } } 6.18 #include<stdio.h> void main() { int i,Count; Count=0; for(i=1;i<=100;i++) { if(i%2!=0 && i%3!=0) { Count=Count+1; printf("%d",i); } printf("%dn",Count); } }
  • 42. 42 Chapter 9 9.3 #include<stdio.h> #include<math.h> int Fact(int n) { if(n==0) return 1; else return (n*Fact(n-1)); } float Fx(int x) { float Result=0; int i,j,Temp1,Temp2; for(i=1,j=1;i<=5;i+=2,j++) { if(j%2!=0) { Temp1 = pow(x,i); Temp2 = Fact(i); Result += (float) Temp1/Temp2; } else { Temp1 = pow(x,i); Temp2 = Fact(i); Result -= (float) Temp1/Temp2; } } return Result; } void main() { int No; float F;
  • 43. 43 printf("Enter a Number-->n"); scanf("%d",&No); F = Fx(No); printf("Result--> %f",F); } 9.7 int prime(int x) { int i; for(i=2;i<=x/2;i++) { if(x%i==0) return 0; } return 1; } void main() { int n,c; printf("Enter a Number-->n"); scanf("%d",&n); c = prime(n); if(c==1) printf("nNumber %d is Prime",n); else printf("nNumber %d is Not Prime",n); }
  • 44. 44 9.10 #include<math.h> #include<stdio.h> int a,b,c; void Read() { printf("Enter three sides of Triangle-->n"); scanf("%d %d %d",&a,&b,&c); } void Area() { double S,Area,Temp; S=(double) (a+b+c)/2; Area=sqrt((S-a)*(S-b)*(S-c)); printf("Area of Triangle:--> %lf",Area); } void Peri() { int P; P=a+b+c; printf("Perimeter of Triangle:--> %d",P); } void main() { int ch; Read(); while(1) { printf("1. Area n2. Perimeter n3. Exitn"); printf("Enter UR Choicen"); scanf("%d",&ch); switch(ch) { case 1: Area(); break;
  • 45. 45 case 2: Peri(); break; default: break; } } } 9.11 #include<stdio.h> #define MAX 10 int Largest(int a[][MAX],int m,int n) { int Large,i,j; Large=a[0][0]; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(Large<a[i][j]) Large=a[i][j]; } } return Large; } void main() { int A[MAX][MAX]; int L,m,n,i,j; printf("Enter Number of Rowsn"); scanf("%d",&m); printf("Enter Number of Columnsn"); scanf("%d",&n); printf("Enter Elements of Matrix:--n");
  • 46. 46 for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&A[i][j]); } } printf("Matrix is:--n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",A[i][j]); } } L = Largest(A,m,n); printf("nLargest Element :-- %d",L); } 9.12 #include<stdio.h> #include<conio.h> #define MAX 10 void Multiplication(int a[][MAX],int b[][MAX],int m,int n1) { int c[MAX][MAX],i,j,k; for(i=0;i<m;i++) { for(j=0;j<n1;j++) { c[i][j]=0; for(k=0;k<m;k++) c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } }
  • 47. 47 printf("Multiplication of Matrices is:--n"); for(i=0;i<m;i++) { for(j=0;j<n1;j++) { printf("%d ",c[i][j]); } printf("n"); } } void main() { int A[MAX][MAX],B[MAX][MAX]; int L,m,n,m1,n1,i,j; clrscr(); printf("Enter Number of Rows & Columns First Matrixn"); scanf("%d %d",&m,&n); printf("Enter Number of Rows & Columns of Second Matrixn"); scanf("%d %d",&m1,&n1); if(m==n1) { printf("Enter Elements of First Matrix:--n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&A[i][j]); } } printf("Enter Elements of Second Matrix:--n"); for(i=0;i<m1;i++) { for(j=0;j<n1;j++) { scanf("%d",&B[i][j]); } } clrscr();
  • 48. 48 printf("First Matrix is:--n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",A[i][j]); } printf("n"); } printf("Second Matrix is:--n"); for(i=0;i<m1;i++) { for(j=0;j<n1;j++) { printf("%d ",B[i][j]); } printf("n"); } Multiplication(A,B,m); } else printf("Multiplication is not applicablen"); getch(); } “Good code is its own best documentation. As you're about to add a comment, ask yourself, "How can I improve the code so that this comment isn't needed?" Improve the code and then document it to make it even clearer. ” - Steve McConnell “Programming can be fun, so can cryptography; however they should not be combined.” - Kreitzberg and Shneiderman “Copy and paste is a design error.” - David Parnas
  • 49. 49