You are on page 1of 46

C OPERATORS

C programs
PROGRAM 1
WAP to read two integers, calculate sum, difference, product and division of them and display the results

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,add,sub,mul;
float div;
printf(“enter the value of a and b”);
scanf(“%d %d”,&a,&b);
add=a+b;
sub =a-b;
mul=a*b;
div=a/b;
printf(“%d %d %d”,add,sub,mul);
printf(“%f”,div);
getch( );
}
PROGRAM 2
WAP to read base and height of a triangle , calculate the area using formula area =1/2*base*height

#include<stdio.h>
#include<conio.h>
void main( )
{
float b,h,area=0.0;
printf(“enter the value of b and h”);
scanf(“%f%f”,&b,&h);
area=(b*h)/2;
printf(“area is =%f”,area);
getch();
}
PROGRAM 3
WAP to check whether a number is palindrome or not
#include<stdio.h>
#include<conio.h>
void main( )
{long int n,num,mod,rev=0;
printf(“program to check whether the number is palindrome or not”);
printf(“enter the number”);
n=num;
while(num>0)
{ mod=num%10;
rev= rev*10+mod;
num=num/10;
}
if(n==rev)
{printf(“no. is palindrome”);}
else
{
PROGRAM 4
WAP to Consider two input variables ‘a’ and ‘b’ and write a program to swap these two numbers

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,temp=0;
printf(“enter the value of a and b”);
scanf(“%d %d”,&a,&b);
temp=a;
a=b;
b=temp;
printf(“%d %d”,a,b);
}
PROGRAM 5
Wap to compute square of (a+b)

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c=0;
printf(“enter the value of a and b”);
scanf(“%d %d”,&a,&b);
c=(a*a)+(b*b)+(2*a*b);
printf(“%d”,c);
}
PROGRAM 6

Wap to compute (a+b)3

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c=0;
printf(“enter the value of a and b”);
scanf(“%d %d”,&a,&b);
c=(a*a*a)+(b*b*b)+(3*a*b)(a+b);
printf(“%d”,c);
}
PROGRAM 7
WAP to find volume of sphere.

#include<stdio.h>
#include<conio.h>
void main( )
{
int r;
float v;
printf(“enter the value of r”);
scanf(“%d ,&r);
v=4/3*pi*r*r*r;
printf(“%f”,v);
}

You might also like