E- Balagurusamy

Programming in C ANSI Exercise Solution Accourding to chapter

Chapter -1

1.1)Write a Program that will print your mailing address in the following form
First line   :  Name
Second line  :  Door No,Street
Third line   :  City,Pincode
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Name:Arifur Rahman.\nVill:Alimabad. Post:Songsabad.\nBarisal,Mehandigonj");
getch();
}
1.2)Modify the above program to provide border lines to the address.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" ____________________________________\n");
printf("|                                    |\n");
printf("|Name:Arifur Rahman.                 |\n");
printf("|Vill:Alimabad. Post:Songsabad.      |\n");
printf("|Barisal,Mehandigonj                 |\n");
printf(" ------------------------------------\n");
getch();
}
1.3)Write a program using one print statement to print the pattern of asterisks as shown below:
*
* *
* * *
* * * *
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n*\n\n*  *\n\n*  *  *\n\n*  *  *  *\n");
getch();
}
1.4)Write a program that will print the following figure using suitable characters.
#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 printf("Figure:\n");
 printf("_____________           ______________\n");
 printf("|           |           |            |\n");
 printf("|           |           |            |\n");
 printf("|           | >>----->  |            |\n");
 printf("|           |           |            |\n");
 printf("|           |           |            |\n");
 printf("~~~~~~~~~~~~~           ~~~~~~~~~~~~~~\n");
 getch();
}
1.5)Give the radious of a circle, write a program to compute and display its area. Use a symbolic constraint to define the Π value are assume a suitable value for radius.
#include<stdio.h>
#include<conio.h>
#define pi 3.1416
void main()
{
 clrscr();
 float area,n;
 printf("\nEnter the radius of the circle:");
 scanf("%f",&n);
 area=pi*pow(n,2);
 printf("The area is=%f",area);
 getch();
}
1.6)Write a program to output the following multiplication table:
.
                   5 × 1 = 5
                   5 × 2 = 10
                   5 × 3 = 15
                     .     .
                     .     .
                   5 × 10 = 50
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
for(int j=1;j<=10;j++)
printf("5 x %d=%d\n\n",j,(5*j));
getch();
}
1.7)Give two integers 20 & 100, write a program that uses a function add() to add this two number and sub to fiend the difference of these two numbers and then display the sum and difference in the following form :
                      20+10=30
                      20-10=10
Solution :
#include<stdio.h>
#include<conio.h>
void add(int a,int b)
{
int c;
c=a+b;
printf("%d+%d=%d\n",a,b,c);
}
void sub(int a,int b)
{
int c;
c=a-b;
printf("%d-%d=%d",a,b,c);
}
void main()
{
clrscr();
int a,b;
printf("\nEnter two number's:");
scanf("%d%d",&a,&b);
add(a,b);
sub(a,b);
getch();
}
1.8)Give the values of three variables a, b, and c, write a program to compute and display the value of x, where
            x=a/(b-c)
Execute your program for the following values :
a) a=250, b=85, c=25
b) a=300, b=70, c=70
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c,x;
printf("\nEnter three value's:");
scanf("%f%f%f",&a,&b,&c);
if(!(b-c))
printf("X=ì");
else
{
x=a/(b-c);
printf("X=%f",x);
}
getch();
}

Chapter -2

2.1)Write a program to determine and print the some of the following harmonic series for a given value of n:
           1+1/2+1/3+..................1/n
The value of n should be given interactively through the terminal.
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float i,sum=0,n;
printf("Enter your range:\n");
scanf("%f",&n);
for(i=1;i<=n;i++)
sum=sum+1/i;
printf("sum=%f",sum);
getch();
}
2.2)Write a program to read the price of an item in the decimal from (like 15.95) and print the output in price (like 1595 paise).
Solution :
#include<stdio.h>
#include&ltconio.h>
void main()
{
clrscr();
float a,b,n;
printf("Enter the price of your item:");
scanf("%f",&a);
n=a*100;
printf("your price is %.3f paisa",n);
getch();
}
2.3) Write a program that prints the even numbers from 1 to 100.
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=2;i<=100;i++)
if(!(i%2))
printf("%d ",i);
getch();
}
2.4) Write a program that requests two float type numbers from the user and then divides the first number by the second and display the result along with the numbers.
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c;
printf("\nEnter two float type number:");
scanf("%f%f",&a,&b);
c=a/b;
printf("%.3fö%.3f=%.3f",a,b,c);
getch();
}
2.5) The price of one kg rice is Rs. 16.75 and one kg of sugar is Rs. 15. Write a program to get these values from the user and display the prices as follows:
***LIST OF ITEMS***
Item    Price
Rice    Rs 16.75
Sugar   Rs 15.00
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a,b;
printf("\nEnter the price of rice and sugar in Kg:");
scanf("%f%f",&a,&b);
printf("\n***LIST OF ITEMS***\n");
printf("Item Prize\n");
printf("Rice    Rs%.3f\n",a);
printf("Suger   Rs%.3f",b);
getch();
}

Chapter -3
















































Under construction......................