Вы находитесь на странице: 1из 5

C++ programes:---

1>program for greater than,smaller than

#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
int a,b,c;
clrscr();
cout<<"enter a,b,c";
cin>>a>>b>>c;
if(a>b)
if(a>c)
cout<<"a is greater";
else
cout<<"c is greater";
else
if(b>c)
cout<<"b is greater";
else
cout<<"c is greater";
getch();
return 0;
}

2>program for power(a,b)

#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
int a,b,c;
clrscr();
cout<<"enter a,b";
cin>>a>>b;
c=pow(a,b);
cout<<c;
getch();
return 0;
}

3>program to find area of rectangle and square

#include<stdio.h>
#include<conio.h>

void main()
{
int B,a,b;
float A
clrscr();
printf("\nA");
printf("\nB");
//printf("\nCASE C");
scanf("%d%d%d",&A,&B);
if( A)
{
printf("\ncompute area of rectangle");
printf("\nenter value of a,b");
scanf("%d%d",&a,&b);
A=1/2(a*b);
printf("%f",A);
}
else
{
printf("\ncompute area of squqre");
printf("\nenter value of a,b);
scanf("%d",&a);
B=a*a;
printf("%d",B);
}
getch();
}

4>progarm for equivalence of no.

#include<stdio.h>
#include<conio.h>

void main()
{

int x,y;
clrscr();
scanf("%d",&x);

if(x>5)
y=3;

else

y=4;
printf("%d",y);

getch();
}

5>program for insurance

#include<stdio.h>
#include<conio.h>

void main()
{
char sex,ms;
int age;
clrscr();

printf("enter age,sex,martial ststus");


scanf("%d%c%c%c",&age,&sex,&ms);

if(ms=='M')
printf("driver is insured");
else
{
if(sex=='M')
{
if(age>30)
printf("driver is insured");
else
printf("driver is not insured");

}
else
{
if(age>25)
printf("driver is insured");
else
printf("driver is not insured");

}
}
getch();
}

6>program for calculating profit and loss

#include<stdio.h>
#include<conio.h>

void main()
{
float cost,sell,prof,loss,just_sold;
clrscr();
printf("\nenter selling price");
scanf("%f",&sell);
printf("\nenter cost price");
scanf("%f",&cost);

prof=sell-cost;

if(prof>0)
printf("\nprofit=%f",prof);
else
{
if(prof==0)
printf("\nno gain no loss=%f",just_sold);
else
printf("\nloss=%f",loss);
}

getch();
}

7>program for finding quadratict equations(roots):

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

float a,b,c,discriminant,root1,root2;
clrscr();
printf("i/ values of a,bandc");
scanf("%f,%f,%f",&a,&b,&c);

discriminant=b*b-4*a*c;

if(discriminant<0)
printf("\nroots are imaginary");
else
{
root1=(-b+sqrt(discriminant)/(2.0*a));
root2=(-b-sqrt(discriminant)/(2.0*a));
printf("\nroot1=%f\nroot2=%f",root1,root2);
}
getch();

8>program for swapping the no.s

#include<iostream.h>
#include<conio.h>
main()
{
int c,d;
cout<<"enter c,d";
cin>>c>>d;
d=d+c;
c=d-c;
d=d-c;
cout<<"c="<<c<<"\t"<<"d="<<d;
getch();
return 0;
}

9>program for simple interest

#include<iostream.h>
#include<conio.h>

void main()
{
int p,n;
float r,si;
clrscr();
p=1000;
n=3;
r=8.5;
si=p*n*r/100;

cout<<"si="<<si;

getch();

10>program for addition,multiplication,division and subtraction.


#include<iostream.h>
#include<conio.h>
main()
{
int a,b;
float ans;
clrscr();
cout<<"enter a,b";
cin>>a>>b;
ans=a+b;
cout<<"nadd="<<nans;
ans=a-b;
cout<<"sub="<<ans;
ans=a*b;
cout<<"mul="<<ans;
ans=(float)a/b;
cout<<"div="<<ans;
getch();
return 0;
}

11>program for finding exponent

#include<stdio.h>
#include<conio.h>
#define ACCURACY 0.0001

void main()
{
int n,count;
float x,term,sum;
clrscr();

printf("enter value of x");


scanf("%f",&x);

n=term=sum=count=1;

while(n<=100)
{
term=term*x/n;
sum=sum+term;
count=count+1;

if(term<ACCURACY)
n=999;

else

n=n+1;
}

printf("TERMS=%dSum=%f\n",count,sum);
getch();
}

Вам также может понравиться