Documente Academic
Documente Profesional
Documente Cultură
{fact=1;
sum1=sum1+i;
for(j=1;j<=i;j++)
fact=fact*j;
sum=sum+(sum1/fact);
}
cout<<"Sum="<<sum;
getch();
}
#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<<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