1.1
Hello World Program
3.6
3.8
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello World");
getch();
}
3.2
To illustrate the use of arithmetic
operators.
#include<stdio.h> #include<conio.h> int main() { clrscr(); /*clrscr that means clear the screen*/ int a,b,sum,sub,mul,div,rem; /* they area variables */ printf("enter the value of a and b"); /*this printf is used for questioning to users*/ scanf("%d%d",&a,&b); /*this scanf is used for checking the variables and location also*/ sum=a+b; sub=a-b; /*sum,sub,mul,div,and rem are used as a formulas*/ mul=a*b; div=a/b; rem=a%b; printf("sum =%d",sum); /*this print is used for printing the values*/ printf("\nsub =%d",sub); printf("\nmul =%d",mul); printf("div =%d",div); printf("rem =%d",rem); getch(); }
3.2 Program to illustrate the concept
of relational operators.
#include<stdio.h> #include<conio.h> void main() { int x=3, y=5; double z=5.37; char c='A'; clrscr(); printf("Result 1 =%d",(x+y)>5); printf("\nResult 2=%d",z>=8.0); printf("\nResult 3=%d",c<'B'); printf("\nResult 4=%d",x==5); getch(); }
output:
Result 1 = 1Result 2 = 0Result 3 = 1Result 4 = 0
3.3 Program to illustrate the concept of size of Operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
float b;
double c;
clrscr();
printf("size of integer =%d",size of (a));
printf("size of integer =%d",size of (int));
printf("size of float =%f",size of (float));
printf("size of float =%f",size of (float));
printf("size of double =%c",size of (c));
getch();
}
Output:size of integer = 2
size of integer = 2
size of float = 4
size of float = 4
size of double = 8
Program to find the sum and average of three values.
3.7
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,sum,avg;
clrscr();
printf("enter the three value");
scanf("%f%f%f",&a,&b,&c);
sum=a+b+c;
avg=sum/3;
printf("sum of three values =%f",sum);
printf("Average =%f",avg);
getch();
}
Output:
Enter three values 9 7 6
Sum of three values = 22.000000
Average = 7.333333
Program to convert temperature from degree Fahrenheit to degree Celsius.
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
clrscr();
printf("\n Enter temperature in Fahrenheit");
scanf("%f",&f);
c=(f−32)×5/9;
printf("\n celsius =%f",c);
getch();
}
Output:Enter temperature in fahrenheit 110.6
Celsius = 43.666664
Program to calculate simple interest
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,t,si;
printf("enter the principal amount");
scanf("%f",&p);
printf("enter the rate of interest");
scanf("%f",&r);
printf("enter the time period");
scanf("%f",&t);
si=(p*r*t)/100;
printf("\n Simple interst=%f",si);
getch();
}
Output
Enter the Principal amount: 1200
Enter the rate of interest: 8
Enter the time period : 2
Simple interest= 192
Program to calculate the area of triangle using Hero's Formula.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,s,area;
clrscr();
printf("\n Enter the three sides of triangle ");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s-a)*(s-b)*(s-c));
printf("Area of triangle =%f",area);
getch();
}
Output:Enter the three sides of triangle 4 5 6
Area of triangle = 9.921567
Program to calculate area and cirumference of circle
#include<stdio.h>
#include<conio.h>
void main()
{
float r,area,c;
clrscr();
printf("\n Enter radius of circle :");
scanf("%f",&r);
area=3.14*r*r;
c=2*3.14*r;
printf("\n area of circle is=%f",area);
printf("\n circumference of circle=%f",c);
getch();
}
Output:Enter the radius of circle = 5.5
Area of circle=94.985001
Circumference of circle=34.540001
Program to swap two number using 3rd variable
3.14
Program to swap two number without using 3rd variable
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the first number to swap ");
scanf("%d",&a);
printf("Enter the second number to swap");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("after the value of swapping=%d%d",a,b);
getch();
}
Output:Enter the first no. to swap = 32
Enter the second no. to swap = 42
After swapping the two number are: 42 32
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the first number to swap ");
scanf("%d",&a);
printf("Enter the second number to swap");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("After the swapping two numbers are: %d%d",a,b);
getch();
}
Output:Enter the first no. to swap = 65
Enter the second no. to swap = 45
After swapping the two number are: 45 65
Program to find Greatest number using conditional operators
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the first number");
scanf("%d",&a);
printf("Enter the second number");
scanf("%d",&b);
printf("Enter the third number");
scanf("%d",&c);
(a>b&&a>c)?printf("greatest number is %d",a)
:(b>c&&b>c)?printf("greatest number is %d",b)
:printf("greatest number is :%d",c);
getch();
}
Output:Enter the first number is = 23
Enter the second number is= 44
Enter the third number is = 23
Greatest number is = 44
1.1 Hello World Program 3.2To illustrate the use of arithmetic operators. 3.2 Program to illustrate the concept of relational operators. 3.3 Program to illustrate the concept of size of Operator. 3.6 Program to find the sum and average of three values. 3.7 Program to convert temperature from degree Fahrenheit to degree Celsius. 3.8 Program to calculate simple interest 3.9 Program to calculate the area of triangle using Hero's Formula. 3.10 Program to calculate area and cirumference of circle 3.13 Program to swap two number using 3rd variable 3.14 Program to swap two number without using 3rd variable 3.15 Program to find Greatest number using conditional operators 4.1 Program to demonstrate the concept of getchar() function4.2 Program to demonstrate the concept of putchar() function