Sunteți pe pagina 1din 12

Hey guys this is the file that contains most of the c++ programs we did.

There are some prgs


that are missing. Enjoy
//WAP to check if a number is Armstrong or not
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int c=0,sum=0,num,i,nc1,nc2,digit;
cout<<"Enter the number";
cin>>num;
nc2=nc1=num;
while(nc1>0)
{nc1=nc1/10;
c++;}
while(nc2>0)
{digit=nc2%10;
sum=sum+pow(digit,c);
nc2=nc2/10;}
if(sum==num)
cout<<"Armstrong Number";
else
cout<<"Not an Armstrong Number";
getch();
}
//WAP to interchange 10th and hundredth place digit
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a , b , c, d, e, f, g, h;
cout<<"\n Enter your no.";
cin>>a;
b=(a/100)%10;
c=(a/10)%10;
d=b*10;
e=c*100;
g=b*100;
h=c*10;
f=(a-g-h)+d+e;
cout<<"Interchange 10th and 100th place="<<f;
getch();
1

//WAP to find circumference and area of a circle


#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
float a;
cout<<"Enter Radius";
cin>>a;
cout<<"\n Circumference="<<2*3.14*a;
cout<<"\n Area="<<3.14*a*a;
getch();
}
//WAP to find ASCII value of any character
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
char a;
int b;
cout<<"Enter the character";
cin>>a;
b=a;
cout<<"\n The ASCII Value="<<b;
getch();
}
//1/1!+(1+2)/2!+(1+2+3)/3!+(1+2+3+4)/4!.......
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int fact,i,j,n;
float sum1=0,sum=0;
cout<<"Enter the number of terms=";
cin>>n;
for(i=1;i<=n;i++)
2

{fact=1;
sum1=sum1+i;
for(j=1;j<=i;j++)
fact=fact*j;
sum=sum+(sum1/fact);
}
cout<<"Sum="<<sum;
getch();
}

//Program to find numberber of years,number of months and number of remaining days


#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a;
cout<<"Enter no.of days";
cin>>a;
cout<<a<<" days have "<<a/365<<" years and "<<(a%365)/30<<" months and
"<<(a%365)%30<<" days";
getch();
}
//WAP to convert decimal to binary
#<iostream.h>
#include<conio.h>
void main()
{clrscr();
int n,r;
int col=23,row=2;
cout<<"Enter Decimal Number=";
cin>>n;
cout<<"Binary Number=";
while(n>0)
{r=n%2;
n=n/2;
gotoxy(col,row);
cout<<r;
col--;}
getch();}
//WAP to calculate discount and give final bill
#include<iostream.h>
3

#include<conio.h>
void main()
{clrscr();
float purchase;
cout<<"Purchase Amount=";
cin>>purchase;
if (purchase>=10&&purchase<50)
{cout<<"\n Discount="<<(2.5/100)*purchase;
cout<<"\n Bill Amount="<<purchase-((2.5/100)*purchase);}
else if (purchase>=50&&purchase<75)
{cout<<"\n Discount="<<(5.0/100)*purchase;
cout<<"\n Bill Amount="<<purchase-((5.0/100)*purchase);}
else if (purchase>=75&&purchase<100)
{cout<<"\n Discount="<<(7.5/100)*purchase;
cout<<"\n Bill Amount="<<purchase-((7.5/100)*purchase);}
else if (purchase>=100&&purchase<150)
{cout<<"\n Discount="<<(10.0/100)*purchase;
cout<<"\n Bill Amount="<<purchase-((10.0/100)*purchase);}
else if (purchase>=150)
{cout<<"\n Discount="<<(12.5/100)*purchase;
cout<<"\n Bill Amount="<<purchase-((12.5/100)*purchase);}
else
{cout<<"Unknown Purchase Value";}
getch();
}
//WAP to calculate electricity bill
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
float rent=3.0;
float unit;
cout<<"Enter the current unit";
cin>>unit;
if (unit<=100)
{cout<<"Bill Amount="<<rent+(unit*0.100);}
else if(unit>=100&&unit<=200)
{cout<<"Bill Amount"<<rent+(unit-100)*0.150+(100*0.100);}
else if(unit>=200&&unit<=300)
{cout<<"Bill Amount="<<rent + (unit-200)*0.200 + 100*0.150+ 100*0.100;}
else if(unit>300)
{cout<<"Bill Anount"<<rent + (unit-300)*0.350 + 100*0.200 + 100*0.150 + 100*0.100;}
else
4

{cout<<"Unknown Value of Units";}


getch();
}
//WAP to calculate evensum and oddsum of a given no of terms
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int oddsum=0,evensum=0,n;
cout<<"Enter the number of terms";
cin>>n;
for(int i=1;i<=n;i+=2)
oddsum+=i;
cout<<"\n Odd Sum="<<oddsum;
for(int i=2;i<=n;i+=2)
evensum+=i;
cout<<"\n Even Sum="<<evensum;
getch();
}
//WAP to find sum of the series 1!/x^1+2!/x^2+3!/x^3...
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int fact,x,n,i,j;
float sum=0;
cout<<"Enter the number of terms=";
cin>>n;
cout<<"Enter the value of x=";
cin>>x;
for(i=1;i<=n;i++)
{fact=1;
for(j=1;j<=2*i-1;j++)
{fact=fact*j;}
if(i%2==1)
{sum=sum+(fact/pow(x,i));}
if(i%2==0)
{sum=sum-(fact/pow(x,i));}
}
cout<<"Sum="<<sum;
getch();
}
5

//WAP to find Fibonacci sequence


#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int unsigned i,n,f1=0,f2=1,f3;
cout<<"Enter the number of terms";
cin>>n;
if(n==0)
cout<<"0 terms";
else
{cout<<"\n"<<f1;
for(i=1;i<n;i++)
{cout<<" "<<f2;
f3=f1+f2;
f1=f2;
f2=f3;
}
}
getch();
}
//Program to convert farenheit to centigrade and vice versa
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
float a,b;
char choice;
cout<<"Enter your choice";
cin>>choice;
if (choice=='f'||choice=='F')
{cout<<"Enter the temperature in farenheit";
cin>>a;
cout<<"\n Temperature in centigrade="<<(5.0/9)*(a-32);}
else if (choice=='c'||choice=='C')
{cout<<"Enter the temperature in centigrade";
cin>>b;
cout<<"\n Temperature in farenheit="<<9.0/5*b+32;}
else
{cout<<"Unknown choice";}
getch();
}
6

//WAP to find the grade


#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a;
cout<<"Enter the percentage";
cin>>a;
if(a>=90&&a<101)
{cout<<"Grade="<<'A';}
else if(a>=80)
{cout<<"Grade="<<'B';}
else if(a>=70)
{cout<<"Grade="<<'C';}
else if(a>=60)
{cout<<"Grade="<<'D';}
else if(a>=50)
{cout<<"Grade="<<'E';}
else if(a<50&&a>0)
{cout<<"Grade="<<'F';}
else
{cout<<"Unknown grade";}
getch();
}

//WAP to print hollow pyramid


#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int i,j,k,l,m,n;
cout<<"Enter the number ";
cin>>n;
for(i=1;i<=n-1;i++)
{for(j=i;j<n;j++)
cout<<" ";
cout<<"*";
for(l=1;l<2*i-2;l++)
cout<<" ";
if(i>1)
cout<<" *";
7

cout<<endl;
}
for(k=1;k<=2*n-1;k++)
cout<<"* ";
for(i=n-((n/2)+1);i<=2*n+1;i++)
{for(j=i;j<2*n+1;j++)
cout<<" ";
getch();
}
//Program to extract digit in the hundred's place of an entered number
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a;
cout<<"Enter the number";
cin>>a;
cout<<"The third digit="<<(a/100)%10;
getch();
}
//WAP to print multiplication table
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int product=1,x,i;
cout<<"Enter value of x";
cin>>x;
for(i=1;i<=15;i++)
{product=x*i;
cout<<"\n"<<x<<"*"<<i<<"="<<product;}
getch();
}
//WAP to print odd no. half pyramid
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int i,j,n;
cout<<"Enter the number of rows=";
cin>>n;
8

for(i=1;i<=n;i++)
{for(j=1;j<=2*i-1;j++)
{if(j%2==1)
cout<<j<<" ";
}
cout<<endl;
}
getch();
}
//WAP to check if a given no. is prime or not
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int c=0,n,i;
cout<<"Enter the number";
cin>>n;
if(n==1)
cout<<"\n The number is neither prime or composite";
else
{for(i=1;i<=n/2;i++)
{if(n%i==0)
c++;}
if(c==1)
cout<<"\nNumber is Prime";
else
cout<<"\n Number is Composite";}
getch();
}
//WAP to print yearly production in million barrels a year using eqn.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int i,a,b,c;
for(a=1;a<=50;a++)
{for(b=1;b<=50;b++)
{for(c=1;c<=50;c++)
{if(c==sqrt(pow(a,2)+pow(b,2))&&a>b)
{cout<<a<<","<<b<<","<<c<<endl;}
}
9

}
}
getch();
}
//Program to find quotient and remainder of the 2 I/P values
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b;
cout<<"Enter two values";
cin>>a>>b;
cout<<"\n"<<"Quotient="<<a/b;
cout<<"\n"<<"Remainder="<<a%b;
getch();
}
//1+(x^2/1!)+(x^4/2!)....
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int i,n,x,j;
float fact=1,sum=1;
cout<<"Enter the number of terms=";
cin>>n;
cout<<"Enter the value of x=";
cin>>x;
for(i=2;i<=2*n-2;i+=2)
{fact=1;
for(j=1;j<=i/2;j++)
{fact=fact*j;}
sum=sum+(pow(x,i)/fact);
}
cout<<"Sum="<<sum;
getch();
}
//WAP to identify upper case or lower case and reverse it
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
10

void main()
{clrscr();
char ch,ch1;
cout<<"Enter the character";
cin>>ch;
if(islower(ch))
{cout<<"Lower Case";
ch1 = toupper(ch);
cout<<"\n"<<ch1;}
else if(isupper(ch))
{cout<<"Upper Case";
ch1 = tolower(ch);
cout<<"\n"<<ch1;}
getch();
}
//WAP to print pythagorean triplets
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int a, b,c, d ,e;
for (int i=1 ; i<=50; i++ )
{a=i;
for (int j=1; j<=50; j++)
{b=j;
for (int k=1; k<=50; k++)
{c=k;
d=pow(c,2);
e=pow(a,2)+ pow(b,2);
if (d==e && a>b)
cout<<" The pythagorean triplet in order of a,b,c is "<<a<<" "<<b<<" "<<c<<" "<<"\n";}}}
getch();}
//WAP to find the roots of Q.E
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
float a , b , c;
cout<<"\n Enter the three values of the quadratic eqn";
cin>>a>>b>>c;
11

float d=pow(b,2);
float z=d-(4*a*c);
if(z>=0)
{float y= (-b+sqrt(z))/2*a;
float x= (-b-sqrt(z))/2*a;
cout<<"\n \n The First root="<<x;
cout<<"\n \n The Second root="<<y;}
else
{cout<<"\n No real roots";}
getch();
}
//WAP to find sum of GP
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int n,a;
float sum=0,r ;
cout<<"\n Enter the value of a ";
cin>>a;
cout<<"\n Enter the no.of terms ";
cin>>n;
cout<<"\n Enter the value of r";
cin>>r;
for(int i=0; i<n; i++)
{sum=sum+pow(r,i);}
cout<<"\n Sum = "<<a*sum;
getch();
}
******************************************************************************

12

S-ar putea să vă placă și