SlideShare a Scribd company logo
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

The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
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
BUBT
 
C programs
C programsC programs
C programsMinu S
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Let us c chapter 4 solution
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solution
rohit kumar
 
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
Hazrat Bilal
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
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
BUBT
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
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 Bilal
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
Hazrat Bilal
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar
 
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
Sazzad Hossain, ITP, MBA, CSCA™
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
RAJWANT KAUR
 
C Programming
C ProgrammingC Programming
C Programming
Sumant Diwakar
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
P M Patil
 
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
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 

What's hot (20)

The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
 
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
 
Ansi c
Ansi cAnsi c
Ansi c
 
C programs
C programsC programs
C programs
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Let us c chapter 4 solution
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solution
 
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
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
 
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
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
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
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
 
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 File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
C Programming
C ProgrammingC Programming
C Programming
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
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
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 

Similar to The solution manual of c by robin

'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu
 
C basics
C basicsC basics
C basicsMSc CST
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
Mazedurr rahman
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
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
vrgokila
 
C questions
C questionsC questions
C questions
mohamed sikander
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
mhande899
 
C Programming lab
C Programming labC Programming lab
C Programming lab
Vikram Nandini
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ Eli Diaz
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ Eli Diaz
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65
 

Similar to The solution manual of c by robin (20)

'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C basics
C basicsC basics
C basics
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
7 functions
7  functions7  functions
7 functions
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
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 questions
C questionsC questions
C questions
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
Vcs16
Vcs16Vcs16
Vcs16
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 

Recently uploaded

在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 

Recently uploaded (20)

在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 

The solution manual of c 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++)
  • 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