SOLUTION PROGRAMMING IN ANSI C: CHAPTER-1

Posted: May 21, 2012 in BCSE, Programming C, Uncategorized
Tags: , , , , ,

Problem exercise no 1.1&1.2:
Coding of the programme:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“—————————————\n”);
printf(“I  First line :A.Z.M.Shakilur Rahman  I\nI  Second line :12/a ,Ali sonar lane  I\nI  Third line:Bogra,5800              I\n”);
printf(“—————————————“);
}
Output:
Problem exercise no. 1.3:
Coding of the programme:
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
printf(“*\n* *\n* * *\n* * * * “);
getch();
}
Output:
*
* *
* * *
* * * *
Problem exercise no :1.4
Coding of the problem:

#include<stdio.h>

main()

{

printf(” ___             ___\n|   |           |   |\n|   | >>——> |   |\n|   |           |   |\n|___|           |___|”);      getch();

}

Problem exercise no:1.5
Coding of the problem:

#include<stdio.h>

#define y 3.1416

main()

{

float x,z;

printf(“enter the vule of radios=”);

scanf(“%f”,&x);

z= ((x*x)* y);

printf(“area of the circle=%f”,z);

getch();

}

Output:
ENTER THE RADIUS OF A CIRCLE=2
Area=12.566360 sqr unit
Problem exercise no:1.6
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int b,c;
clrscr();
for(b=1;b<=10;b++)
{
c=5*b;
printf(“\n\t%d*%d=%d\n”,5,b,c);
getch();
}
}
Output :
Problem exercise no:1.7
Coding of the programme:

#include<stdio.h>

#define a 20

#define b 10

main()

{

int c,d;

c=a+b;

d=a-b;

printf(“20+10=%d\n20-10=%d”,c,d);

getch();

}

Output :
            20+10=30
            20-10=10
Problem exercise no:1.8
Coding:

#include<stdio.h>

main ()

{

Float  x,a,b,c;

printf(“Enter the value of a : “);

scanf(“%f”,&a);

printf(“Enter the value of b : “);

scanf(“%f”,&b);

printf(“Enter the value of c : “);

scanf(“%f”,&c);

x=(a/(b-c));

printf(“x=%f”,x);

getch();

}

Output:
a)
Enter values of a,b&c
250
85
25
result=4
b)NO OUTPUT
Problem exercise  no:1.9 (b)
Coding :

#include<stdio.h>

main ()
{
float temp_c, temp_f;

printf (“Enter the value of Temperature in Celcius: “);

scanf (“%f”, &temp_c);

temp_f = (1.8 * temp_c) + 32;

printf (“The value of Temperature in Fahreinheit is: %f”, temp_f);

}

Output :
ENTER TEMPERATURE IN FARENHITE
10
In Celsius scale=-12.222222
Problem exercise  no:1.9 (a)
Coding :
#include<stdio.h>
#include<conio.h>
void main()
{
float a,F,C;
clrscr();
printf(“ENTER TEMPERATURE IN CELSIUS\n”);
scanf(“%f”,&C);
a=(9*C)/5;
F=a+32;
printf(“\nIn farenhite scale=%f”,F);
getch();
}
Output:
ENTER TEMPERATURE IN CELSIUS
10
In frenhite scale=50.00000
Problem exercise  no: 1.10
Coding of the problem:

#include<stdio.h>

#include<math.h>

main()

{

float S,a,b,c,A;

printf(“a=”);

scanf(“%f”,&a);

printf(“b=”);

scanf(“%f”,&b);

printf(“c=”);

scanf(“%f”,&c);

S=((a+b+c)/2);

printf(“S=%f\n”,S);

A=(S*(S-a)*(S-b)*(S-c));

printf(“A=%f”,A);

getch();

}


Sample output:
       ENTER THE THREE SIDES OF A TRIANGLE=10
12
14
       Area of the triangle=58.787754
Problem exercise no:1.11
Coding:

#include<stdio.h>

#include<math.h>

main()

{

int x,x1,y,y1;

float D;

printf(“Enter the value of (x,y) point: \n”);

scanf(“%d%d”,&x,&y);

printf(“Enter the value of (x1,y1) point : \n”);

scanf(“%d%d”,&x1,&y1);

D=sqrt(((x1-x)*(x1-x))+((y1-y)*(y1-y)));

printf(“D=%f”,D);

getch();

}

Output :
ENTER CO-ORDINATES x1,x2,y1,y2=
2
4
8
5
Result=3.605551
Problem exercise no:1.12
Coding:

#include<stdio.h>

#include<conio.h>

#include<math.h>

#define pi 3.14159

int main()

{

float r,x1,x2,y1,y2,A;

x1=0;

x2=0;

y1=4;

y2=5;

r=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

A=pi*r*r;

printf(“Result=%f”,A);

getch();

}

Output :
Result=3.14159
Problem exercise no:1.13
Coding:

#include<stdio.h>

#include<math.h>

#define pi 3.14159

void main()

{

float D,r,x1,x2,y1,y2,A;

x1=2;

x2=2;

y1=5;

y2=6;

D=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

r=D/2;

A=pi*r*r;

printf(“Result=%f”,A);

getch();

}

Output :
Result=0.785398
Problem exercise no:1.14
Coding:

#include<stdio.h>

#include<conio.h>

void main()

{ int a,b,c;

clrscr();

a=5;

b=8;

c=18;

printf(“%dx+%dy=%d”,a,b,c);

getch();

}

Output :
5x+8y=18
Problem exercise no:1.15
Coding:

#include<stdio.h>

#include<conio.h>

void main()

{ float x,y,sum,difference,product,division;

clrscr();

printf(“ENTER TWO NUMBERS=\n”);

scanf(“%f%f”,&x,&y);

sum=x+y;

difference=x-y;

product=x*y;

division=x/y;

printf(“\n\tSum=%f\tDifference=%f\n\n\tProduct=%f\tDivision=%f”,sum,difference,product,division);

getch();

}


Output :
ENTER TWO NUMBERS=
10
5
            Sum=15.000000                      Difference=5.000000
            Product=50.000000                Division=2.000000

\n

About these ads
Comments
  1. nigamananda sahu says:

    it is realy helpful for everyone who are following ANSI C book. thanx for such an act.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s