The solution manual of programming in ansi by Robin

solution manual of programming in ansi c by balagurusamy 1-6 Chapters.

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

Recomendados

Chapter 4 : Balagurusamy Programming ANSI in C por
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
7.4K vistas20 diapositivas
Chapter 3 : Balagurusamy Programming ANSI in C por
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C BUBT
14K vistas13 diapositivas
Let us c chapter 4 solution por
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solutionrohit kumar
14.4K vistas4 diapositivas
Chapter 5 Balagurusamy Programming ANSI in c por
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in cBUBT
10.8K vistas36 diapositivas
Chapter 2 : Balagurusamy_ Programming ANsI in C por
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in CBUBT
5.5K vistas14 diapositivas
Chapter 1 : Balagurusamy_ Programming ANsI in C por
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C BUBT
6.5K vistas13 diapositivas

Más contenido relacionado

La actualidad más candente

Chapter 8 c solution por
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
9.1K vistas87 diapositivas
LET US C (5th EDITION) CHAPTER 2 ANSWERS por
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
574 vistas22 diapositivas
C Programming Storage classes, Recursion por
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, RecursionSreedhar Chowdam
379 vistas34 diapositivas
Character Array and String por
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
958 vistas27 diapositivas
C and C++ functions por
C and C++ functionsC and C++ functions
C and C++ functionskavitha muneeshwaran
1.3K vistas37 diapositivas
Let us C (by yashvant Kanetkar) chapter 3 Solution por
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 SolutionHazrat Bilal
28.3K vistas14 diapositivas

La actualidad más candente(20)

Chapter 8 c solution por Azhar Javed
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed9.1K vistas
LET US C (5th EDITION) CHAPTER 2 ANSWERS por KavyaSharma65
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65574 vistas
C Programming Storage classes, Recursion por Sreedhar Chowdam
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam379 vistas
Character Array and String por Tasnima Hamid
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid958 vistas
Let us C (by yashvant Kanetkar) chapter 3 Solution por Hazrat Bilal
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
Hazrat Bilal28.3K vistas
Object Oriented Programming Using C++ Practical File por Harjinder Singh
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh14.9K vistas
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search) por Make Mannan
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Make Mannan4K vistas
C programs por Minu S
C programsC programs
C programs
Minu S8.5K vistas
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution por Hazrat Bilal
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal4.4K vistas
Core programming in c por Rahul Pandit
Core programming in cCore programming in c
Core programming in c
Rahul Pandit6.2K vistas

Destacado

Important C program of Balagurusamy Book por
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy BookAbir Hossain
1.8K vistas11 diapositivas
Programming in ansi C by Balaguruswami por
Programming in ansi C by BalaguruswamiProgramming in ansi C by Balaguruswami
Programming in ansi C by BalaguruswamiPriya Chauhan
25.5K vistas116 diapositivas
How to program with c in persian por
How to program with c in persianHow to program with c in persian
How to program with c in persianmoein jazemi
195 vistas114 diapositivas
C interview-questions-techpreparation por
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparationKushaal Singla
2.7K vistas16 diapositivas
IS740 Chapter 05 por
IS740 Chapter 05IS740 Chapter 05
IS740 Chapter 05iDocs
2.9K vistas60 diapositivas
Unit 1 water_technology por
Unit 1 water_technologyUnit 1 water_technology
Unit 1 water_technologyKushaal Singla
41K vistas69 diapositivas

Destacado(9)

Important C program of Balagurusamy Book por Abir Hossain
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
Abir Hossain1.8K vistas
Programming in ansi C by Balaguruswami por Priya Chauhan
Programming in ansi C by BalaguruswamiProgramming in ansi C by Balaguruswami
Programming in ansi C by Balaguruswami
Priya Chauhan25.5K vistas
How to program with c in persian por moein jazemi
How to program with c in persianHow to program with c in persian
How to program with c in persian
moein jazemi195 vistas
C interview-questions-techpreparation por Kushaal Singla
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
Kushaal Singla2.7K vistas
IS740 Chapter 05 por iDocs
IS740 Chapter 05IS740 Chapter 05
IS740 Chapter 05
iDocs2.9K vistas
C notes.pdf por Durga Padma
C notes.pdfC notes.pdf
C notes.pdf
Durga Padma41.5K vistas
Introduction to Pseudocode por Damian T. Gordon
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
Damian T. Gordon339.4K vistas
Algorithmsandflowcharts1 por luhkahreth
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
luhkahreth49.7K vistas

Similar a The solution manual of programming in ansi by Robin

C Programming Exam problems & Solution by sazzad hossain por
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainSazzad Hossain, ITP, MBA, CSCA™
1.6K vistas32 diapositivas
Practical write a c program to reverse a given number por
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 numberMainak Sasmal
9.9K vistas98 diapositivas
Practical write a c program to reverse a given number por
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 numberMainak Sasmal
2.4K vistas104 diapositivas
Program flowchart por
Program flowchartProgram flowchart
Program flowchartSowri Rajan
27 vistas13 diapositivas
'C' language notes (a.p) por
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
6.2K vistas16 diapositivas
Data Structure using C por
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
914 vistas44 diapositivas

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

Practical write a c program to reverse a given number por Mainak Sasmal
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 Sasmal9.9K vistas
Practical write a c program to reverse a given number por Mainak Sasmal
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 Sasmal2.4K vistas
'C' language notes (a.p) por Ashishchinu
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu6.2K vistas
Data Structure using C por Bilal Mirza
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza914 vistas
Assignment on Numerical Method C Code por Syed Ahmed Zaki
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki7.6K vistas
C basics por MSc CST
C basicsC basics
C basics
MSc CST322 vistas
Basic c programs updated on 31.8.2020 por vrgokila
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila147 vistas
Practical File of C Language por RAJWANT KAUR
Practical File of C LanguagePractical File of C Language
Practical File of C Language
RAJWANT KAUR33.5K vistas
C lab manaual por manoj11manu
C lab manaualC lab manaual
C lab manaual
manoj11manu1.9K vistas
C faq pdf por DebiPanda
C faq pdfC faq pdf
C faq pdf
DebiPanda1.2K vistas
Simple C programs por ab11cs001
Simple C programsSimple C programs
Simple C programs
ab11cs0013.1K vistas
4 operators, expressions &amp; statements por MomenMostafa
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa102 vistas

Más de Shariful Haque Robin

Super-Structural Construction Work of a Six Storied Residential Building. por
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.Shariful Haque Robin
4.1K vistas55 diapositivas
Analysis and Design of Structural Components of a Ten Storied RCC Residential... por
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...Shariful Haque Robin
19.3K vistas87 diapositivas
Cracking in Reinforced Concrete Flexural Members (by Robin) por
Cracking in Reinforced Concrete Flexural Members (by Robin)Cracking in Reinforced Concrete Flexural Members (by Robin)
Cracking in Reinforced Concrete Flexural Members (by Robin)Shariful Haque Robin
4.1K vistas25 diapositivas
Bangladeshi Rail (by Robin) por
Bangladeshi Rail (by Robin)Bangladeshi Rail (by Robin)
Bangladeshi Rail (by Robin)Shariful Haque Robin
3.6K vistas66 diapositivas
Super-Structural Construction Work of a Six Storied Residential Building por
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 BuildingShariful Haque Robin
5.5K vistas80 diapositivas
Construction work of a multi storied residential building por
Construction work of a multi storied residential buildingConstruction work of a multi storied residential building
Construction work of a multi storied residential buildingShariful Haque Robin
28.7K vistas43 diapositivas

Más de Shariful Haque Robin(11)

Super-Structural Construction Work of a Six Storied Residential Building. por Shariful Haque Robin
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.
Shariful Haque Robin4.1K vistas
Analysis and Design of Structural Components of a Ten Storied RCC Residential... por Shariful Haque Robin
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...
Shariful Haque Robin19.3K vistas
Cracking in Reinforced Concrete Flexural Members (by Robin) por Shariful Haque 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)
Shariful Haque Robin4.1K vistas
Super-Structural Construction Work of a Six Storied Residential Building por Shariful Haque Robin
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
Shariful Haque Robin5.5K vistas
Construction work of a multi storied residential building por Shariful Haque Robin
Construction work of a multi storied residential buildingConstruction work of a multi storied residential building
Construction work of a multi storied residential building
Shariful Haque Robin28.7K vistas
LOW VOLTAGE ELECTRIC ELEMENT IS USED IN HIGH VOLTAGE SOURCE por Shariful Haque Robin
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

Último

Control Systems Feedback.pdf por
Control Systems Feedback.pdfControl Systems Feedback.pdf
Control Systems Feedback.pdfLGGaming5
6 vistas39 diapositivas
K8S Roadmap.pdf por
K8S Roadmap.pdfK8S Roadmap.pdf
K8S Roadmap.pdfMaryamTavakkoli2
6 vistas1 diapositiva
Instrumentation & Control Lab Manual.pdf por
Instrumentation & Control Lab Manual.pdfInstrumentation & Control Lab Manual.pdf
Instrumentation & Control Lab Manual.pdfNTU Faisalabad
5 vistas63 diapositivas
Digital Watermarking Of Audio Signals.pptx por
Digital Watermarking Of Audio Signals.pptxDigital Watermarking Of Audio Signals.pptx
Digital Watermarking Of Audio Signals.pptxAyushJaiswal781174
12 vistas25 diapositivas
DevOps-ITverse-2023-IIT-DU.pptx por
DevOps-ITverse-2023-IIT-DU.pptxDevOps-ITverse-2023-IIT-DU.pptx
DevOps-ITverse-2023-IIT-DU.pptxAnowar Hossain
9 vistas45 diapositivas
Saikat Chakraborty Java Oracle Certificate.pdf por
Saikat Chakraborty Java Oracle Certificate.pdfSaikat Chakraborty Java Oracle Certificate.pdf
Saikat Chakraborty Java Oracle Certificate.pdfSaikatChakraborty787148
15 vistas1 diapositiva

Último(20)

Control Systems Feedback.pdf por LGGaming5
Control Systems Feedback.pdfControl Systems Feedback.pdf
Control Systems Feedback.pdf
LGGaming56 vistas
Instrumentation & Control Lab Manual.pdf por NTU Faisalabad
Instrumentation & Control Lab Manual.pdfInstrumentation & Control Lab Manual.pdf
Instrumentation & Control Lab Manual.pdf
NTU Faisalabad 5 vistas
zincalume water storage tank design.pdf por 3D LABS
zincalume water storage tank design.pdfzincalume water storage tank design.pdf
zincalume water storage tank design.pdf
3D LABS5 vistas
MSA Website Slideshow (16).pdf por msaucla
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdf
msaucla68 vistas
What is Whirling Hygrometer.pdf por IIT KHARAGPUR
What is Whirling Hygrometer.pdfWhat is Whirling Hygrometer.pdf
What is Whirling Hygrometer.pdf
IIT KHARAGPUR 12 vistas
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... por AakashShakya12
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
AakashShakya1272 vistas
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ... por AltinKaradagli
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
AltinKaradagli9 vistas
Machine Element II Course outline.pdf por odatadese1
Machine Element II Course outline.pdfMachine Element II Course outline.pdf
Machine Element II Course outline.pdf
odatadese19 vistas

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