Source code :
1.To display two number :
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
printf("Enter the number\n");
scanf("%d %d",&a,&b);
printf("The numbers are %d %d",a,b);
getch();
}
Output:
Here we use & to address the the variable a,b.
int a,b means a and b are integer.
2, Calculation of Simple Interest :
#include<stdio.h>
#include<conio.h>
int main()
{
int p,t,r,si;
printf("Enter the principle,time,rate\n");
scanf("%d %d %d",&p,&t,&r);
si=p*t*r/100;
printf("The si is %d",si);
getch();
}
Output:
Here we use 3 %d because we have to give the value of 3 numbers and we have to find the value of one si so the is 1 %d at the last printf before getch.
And * means multiplication.
Hope you have understood.
3. Program to add two numbers :
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,sum;
printf("Enter the two number\n");
scanf("%d %d",&a,&b);
sum=a+b;
printf("The sum of two number is %d",sum);
getch();
}
Output:
3. Program to add two numbers :
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,sum;
printf("Enter the two number\n");
scanf("%d %d",&a,&b);
sum=a+b;
printf("The sum of two number is %d",sum);
getch();
}
Output:
4. Program to find area and circumference of circle :
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int A,C,r;
printf("Enter the radius\n");
scanf("%d",&r);
A=3.14*pow(r,2);;
C=2*3.14*r;
printf("The area and circumference is %d %d",A,C);
getch();
}
Here we use #include<math.h> because we know the area of circle is pi(3.14)*r*r
so for easy or for terms having their power greater than 1 we can write #include<math.h>.
Also there is 2 %d at last printf as we have to give the output of two terms A and C .
Or we can simply write
#include<stdio.h>
#include<conio.h>
int main()
{
int A,C,r;
printf("Enter the radius\n");
scanf("%d",&r);
A=3.14*r*r; You can notice here we have not used pow
C=2*3.14*r;
printf("The area and circumference is %d %d",A,C);
getch();
}
Output:
Here we have not obtained decimal form as we used interger but if we used float we can obtained decimal form i.e:
#include<stdio.h>
#include<conio.h>
int main()
{
int r;
float A,C;
printf("Enter the radius\n");
scanf("%d",&r);
A=3.14*r*r;
C=2*3.14*r;
printf("The area and circumference is %f %f",A,C);
getch();
}
Output:
5. Program to convert Celsius into Farenheit
#include<stdio.h.>
#include<conio.h>
void main()
{
float C,F;
printf("Enter the temperature in celsius\n");
scanf("%f",&C);
F=1.8*C+32;
printf("The req Farenheit is %f",F);
getch();
}
Output:

Float gives the output after the decimal upto 6 digits .eg:4.000897
No comments :
Post a Comment