C Program
C Program
EXERCISE 1:SUM
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter two value:\n");
scanf("%d%d",&a,&b);
c=a+b;
printf("The result is= %d",c);
getch();
}
OUTPUT:
Enter two value:
22
44
The result is= 66
EXERCISE 2:SUB
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter two value:\n");
scanf("%d%d",&a,&b);
c=a-b;
printf("The result is= %d",c);
getch();
}
OUTPUT:
Enter two value:
100
50
The result is= 50
EXERCISE 3 : MULTIPLY
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter two value:\n");
scanf("%d%d",&a,&b);
c=a*b;
printf("The result is= %d",c);
getch();
}
OUTPUT:
Enter two value:
50
50
The result is= 2500
EXERCISE 4: DIVISION
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter two value:\n");
scanf("%d%d",&a,&b);
c=a/b;
printf("The result is= %d",c);
getch();
}
OUTPUT:
Enter two value:
1000
10
The result is= 100
#include<stdio.h>
main()
{
int a,b;
printf("Enter two values\n");
scanf("%d%d",&a,&b);
printf("\n The sum = %d",a+b);
printf("\n The difference = %d",a-b);
printf("\n The product = %d",a*b);
printf("\n The Division = %d",a/b);
getch();
}
OUTPUT:
Enter two values
100
50
OUTPUT:
enter value fahrenheit
98
celsius is 36.666668
#include<stdio.h>
main()
{
int r;
float pi=3.14,area;
printf("Enter the radius of circle\n");
scanf("%d",&r);
area=pi*r*r;
printf("Area of circle is %f",area);
getch();
}
OUTPUT:
Enter the radius of circle
8
Area of circle is 200.960007
CONDITIONAL OPERATION:
EXERCISE 1:(IF)
#include<stdio.h>
main()
{
int a,b;
a=10;
b=8;
if(a>b)
{
printf("True");
}
else
{
printf("False");
}
getch();
}
OUTPUT:
True
#include<stdio.h>
main()
{
int a=10;
int b=8;
if(a==b)
{
printf("lavanya");
}
else if(a<b)
{
printf("bala");
}
else
{
printf("aashlin");
}
getch();
}
OUTPUT:
Aashlin
#include<stdio.h>
main()
{
int a=10,b=8;
if(a==b)
{
if(a>b)
{
printf("swetha");
}
else
{
printf("not swetha");
}}
else
{
printf("kavitha");
}getch();
}
OUTPUT:
Kavitha
EXERCISE 4: (BIGGEST/ SMALLEST NUMBER USING IF CONDITION)
#include<stdio.h>
main()
{
int a=20,b=40;
if(a>b)
{
printf("A is bigger value");
}
else
{
printf("B is bigger value");
}getch();
}
OUTPUT:
B is bigger value
#include<stdio.h>
main()
{
int num;
printf("Enter the number ");
scanf("%d",&num);
if(num%2==0)
{
printf(" Even number");
}else
{
printf("Odd number");
}getch();
}
OUTPUT:
Enter the number 50
Even number
OUTPUT:
#include<stdio.h>
main()
{
int num1,num2;
char op;
printf("enter the number1");
scanf("%d",&num1);
printf("enter the number2");
scanf("%d",&num2);
printf("\n Enter operator:");
scanf("\n %c",&op);
if(op=='+')
{
printf("The sum=%d",num1+num2);
}
else if(op=='-')
{
printf("The sum=%d",num1-num2);
}else if(op=='*')
{
printf("The sum=%d",num1*num2);
}else if(op=='/')
{
printf("The sum=%d",num1/num2);
}else
{
printf("number is invalid");
}getch();
}
OUTPUT:
Enter operator:*
The sum=2500
OUTPUT:
Enter the year1990
not leap year
#include<stdio.h>
main()
{
int num1,num2;
char op;
printf("enter the number1");
scanf("%d",&num1);
printf("enter the number2");
scanf("%d",&num2);
printf("\n Enter operator:");
scanf("\n %c",&op);
switch(op)
{
case '+':
printf("The sum value=%d",num1+num2);
break;
case '-':
printf("The sum value=%d",num1-num2);
break;
case '*':
printf("The sum value=%d",num1*num2);
break;
case '/':
printf("The sum value=%d",num1/num2);
break;
default:
printf("invalid operator");
break;
}getch();
}
OUTPUT:
Enter operator:)
invalid operator
OUTPUT:
welcome
welcome
welcome
welcome
welcome
#include<stdio.h>
main()
{
int i,n,sum=0;
printf("Enter the values of N\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("sum=%d",sum);
getch();
}
OUTPUT:
Enter the values of N
55
sum=1540
#include<stdio.h>
main()
{
int i,n,fact=1;
printf("enter the value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("factorial=%d",fact);
getch();
}
OUTPUT:
enter the value of n 5
factorial=120
#include<stdio.h>
main()
{
int i=1,n,sum=0;
printf("Enter the value of n");
scanf("%d",&n);
while(i<=n)
{
sum=sum+i;
i++;
}
printf("sum= %d",sum);
getch();
}
OUTPUT:
Enter the value of n 8
sum= 36
#include<stdio.h>
main()
{
int i=1,n,fact=1;
printf("enter the value of n");
scanf("%d",&n);
do
{
fact=fact*i;
i++;
}
while(i<=n);
printf("\n factorial=%d",fact);
printf(" \n i value %d",i);
getch();
OUTPUT:
enter the value of n 0
factorial=1
i value 2