Program

 

Q.1. WAP to check whether a number is prime or not

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n, i, p=0;

cout<<“Enter any positive integer :”;

cin>>n;

for(i=2;i<=n/2;++i)

{

if(n%i==0)

break;

}

if(n%i==0)

cout<<“Composite”;

else

cout<<“Prime”;

getch();

}

 

Q.2. WAP to print prime no. in a given range

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n, r, i, p=0;

cout<<“Enter the range to print prime numbers :”;

cin>>r;

cout<<“The prime numbers are :”;

for(n=1;n<=r;n++)

{

for(i=2;i<=n/2;i++)

{

if(n%i==0)

{

p=1;

break;

}

else

p=0;

}

if(p==0)

cout<<n<<” “;

}

getch();

}

 

Q.3. WAP to print HCF

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a, b, i, hcf;

cout<<“Enter two integers”;

cin>>a>>b;

for(i=1;i<=a || i<=b; ++i)

{

if(a%i==0 && b%i==0)

hcf=i;

}

cout<<hcf;

getch();

}

 

Q.4. WAP to print Fibonacci series

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float first,second,third,n;

int i;

first=0;

second=1;

cout<<“How many elements? \n”;

cin>>n;

cout<<“fibonacci series\n”;

cout<<first<<” “<<second;

for(i=2;i<n;i++)

{

third=first+second;

cout<<” “<<third;

first=second;

second=third;

}

getch();

}

 

 

Q.5. WAP to check whether a no. is amstrong or not

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i, a, b, c;

for(i=1;i<=500;i++)

{

a=i/100;

b=i/10-a*10;

c=i%10;

if((a*a*a)+(b*b*b)+(c*c*c)==i)

cout<<i<<“\n”;

}

getch();

}

 

Q.6. WAP to print 100 even no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

for(int i=2;i<=100;i++)

{

if(i%2==0)

cout<<i<<“\n”;

}

getch();

}

 

 

Q.7. WAP to print 100 odd no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

for (int i=1;i<=100;i++)

{

if(i%2!=0)

cout<<i<<“\n”;

}

getch();

}

 

Q.8. WAP to print 100 multiples of entered no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,multiples=1;

cout<<“enter the no.”;

cin>>n;

for(int i=1;i<=10;i++)

{

multiples=i*n;

cout<<multiples<<“\n”;

}

getch();

}

 

Q.9. WAP to enter a no. and find

(i)Sum of digits

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int a, s=0;

cout<<“Enter any number :”;

cin>>a;

for(;a>0;)

{

 

s+=a%10;

a/=10;

}

cout<<s;

getch();

}

 

(ii)Sum of odd digits

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int a, s=0;

cout<<“Enter any number :”;

cin>>a;

for(;a>0;)

{

if((a%10)%2==1)

s+=a%10;

a/=10;

}

cout<<“The sum of odd digits is :”<<s;

getch();

}

 

(iii)Sum of even digits

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int a, s=0;

cout<<“Enter any number :”;

cin>>a;

for(;a>0;)

{

if((a%10)%2==0)

s+=a%10;

a/=10;

}

cout<<“The sum of even digits is :”<<s;

getch();

}

 

(iv)Sum of digits at odd places

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a, p=0, s=0;

cout<<“Enter any number :”;

cin>>a;

for(;a>0;)

{

p=(p*10)+(a%10);

a=a/10;

}

for(;p>0;)

{

s+=(p%100)%10;

p=p/100;

}

cout<<“The sum of digits at odd places is :”<<s;

getch();

}

 

(v)Sum of digits at even places

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a, p=0, s=0;

cout<<“Enter any number :”;

cin>>a;

for(;a>0;)

{

p=(p*10)+(a%10);

a=a/10;

}

for(;p>0;)

{

s+=(p%100)/10;

p=p/100;

}

cout<<“The sum of digits at even places is :”<<s;

getch();

}

 

Q.10.WAP to print reverse a no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a, b, c, d;

cout<<“Enter any three digit number”;

cin>>a;

b=a%10;

c=((a-b)%100)/10;

d=a/100;

cout<<d<<c<<b;

getch();

}

 

Q.11. WAP to calculate discount for a snapdeal scheme as given below

(i)Purchasing for 0 to 5000 10% discount with additional              cash back of 5% for SBI card

(ii)5000 to 10000 15% discount

cb=6.5%

(iii)10000 to 20000 20% discount

cb=10%

(iv)20000 and above 25% discount

cb=12.5%

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int s,cb,sb;

cout<<“enter the amount of goods purchased: “;

cin>>s;

cb=(s>20000?0.25*s:(s>10000?0.2*s:(s>5000?0.15*s:0.1*s)));

cout<<“Casback is: “<<cb;

sb=(s>20000?0.125*s:(s>10000?0.1*s:(s>5000?0.065*s:0.05*s)));

cout<<“\nAdditional cashback for SBI card user:”<<sb;

getch();

}

 

Q.12. WAP to enter the grade point and print the grade

0 to 3.3        F

3.3 to 4.5     E

4.5 to 5.9     D

6.0 to 7.5     C

7.6 to 8.9     B

9.0 to 10.0   A

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int s;

char cb;

cout<<“Enter CGPA: “;

cin>>s;

cb=(s>8.9?’A’:(s>7.6?’B’:(s>5.9?’C’:(s>4.5?’D’:(s>3.3?’E’:’F’)))));

cout<<“Grade is: “<<cb;

getch();

}

 

 

Q.14. WAP to print 3 no. and output the greatest

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float x, y, z;

cout<<“Enter the three distinct numbers:”;

cin>>x>>y>>z;

if(x>y)

{

if(x>z)

cout<<x<<” is greatest among them”;

}

else

{

if(z>y)

cout<<z<<” is the greatest among them”;

else

cout<<y<<” ts greatest among them”;

}

getch();

}

 

Q.15 WAP to print  3 no. and print the 2nd smallest and 2nd greatest.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float x, y, z;

cout<<“Enter the three distinct numbers:”;

cin>>x>>y>>z;

if(x>y)

{

if(x>z)

{

if(z>y)

cout<<z<<” is 2nd smallest 2nd greatest”;

else

cout<<y<<” is 2nd greatest 2nd smallest”;

}

else

cout<<x<<” is 2nd smallest and 2nd greatest”;

}

else

{

if(z>y)

cout<<y<<” is 2nd greatest and 2nd smallest”;

else

cout<<z<<” is 2nd greatest and 2nd smallest”;

}

getch();

}

 

Q.16. WAP to enter the character and check whether it is alphabet , uppercase , lowercase etc.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char a;

cout<<“Enter the character:”;

cin>>a;

if(a>=’a’&&a<=’z’)

cout<<“Lower case alphabet”;

else

{

if(a>=’A’&&a<=’Z’)

cout<<“Upper Case alphabet”;

else

cout<<“Special Character”;

}

getch();

}

 

Q.17. WAP to print the name of entered no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int a, o, t, h, th, t_th;

o=t=h=th=t_th=-1;

cout<<“Enter any number from 0 to 99999 :”;

cin>>a;

if(a/10000!=0 && a/100000==0)

{

o=a%10;

t=((a-o)%100)/10;

h=((a-t)%1000)/100;

th=((a-h)%10000)/1000;

t_th=a/10000;

}

else if(a/1000!=0 && a/10000==0)

{

o=a%10;

t=((a-o)%100)/10;

h=((a-t)%1000)/100;

th=a/1000;

}

else if(a/100!=0 && a/1000==0)

{

o=a%10;

t=((a-o)%100)/10;

h=a/100;

}

else if(a/10!=0 && a/100==0)

{

o=a%10;

t=a/10;

}

else if(a/10==0)

o=a;

else

{

cout<<“Invalid digits”;

goto end;

}

if(a==0)

{

cout<<“Zero”;

}

switch(t_th)

{

case 1 :switch(th)

{

case 1 :cout<<“Eleven thousand “;

break;

case 2 :cout<<“Twelve thousand “;

break;

case 3 :cout<<“Thirteen thousand “;

break;

case 4 :cout<<“Fourteen thousand “;

break;

case 5 :cout<<“Fifteen thousand “;

break;

case 6 :cout<<“Sixteen thousand “;

break;

case 7 :cout<<“Seventeen thousand “;

break;

case 8 :cout<<“Eight thousand “;

break;

case 9 :cout<<“Nine thousand “;

break;

default:cout<<“Ten thousand “;

break;

}

goto hundred;

case 2 :cout<<“Twenty “;

break;

case 3 :cout<<“Thirty “;

break;

case 4 :cout<<“Forty “;

break;

case 5 :cout<<“Fifty “;

break;

case 6 :cout<<“Sixty “;

break;

case 7 :cout<<“Seventy “;

break;

case 8 :cout<<“Eight “;

break;

case 9 :cout<<“Ninety “;

break;

}

switch(th)

{

case 1 :cout<<“One thousand “;

break;

case 2 :cout<<“Two thousand “;

break;

case 3 :cout<<“Three thousand “;

break;

case 4 :cout<<“Four thousand “;

break;

case 5 :cout<<“Five thousand “;

break;

case 6 :cout<<“Six thousand “;

break;

case 7 :cout<<“Seven thousand “;

break;

case 8 :cout<<“Eight thousand “;

break;

case 9 :cout<<“Nine thousand “;

break;

case 0 :cout<<“Thousand “;

break;

}

hundred:

switch(h)

{

case 1 :cout<<“One hundred “;

break;

case 2 :cout<<“Two hundred “;

break;

case 3 :cout<<“Three hundred “;

break;

case 4 :cout<<“Four hundred “;

break;

case 5 :cout<<“Five hundred “;

break;

case 6 :cout<<“Six hundred “;

break;

case 7 :cout<<“Seven hundred “;

break;

case 8 :cout<<“Eight hundred “;

break;

case 9 :cout<<“Nine hundred “;

break;

 

}

switch(t)

{

case 1 :switch(o)

{

case 1 :cout<<“Eleven”;

break;

case 2 :cout<<“Twelve”;

break;

case 3 :cout<<“Thirteen”;

break;

case 4 :cout<<“Fourteen”;

break;

case 5 :cout<<“Fifteen”;

break;

case 6 :cout<<“Sixteen”;

break;

case 7 :cout<<“Seventeen”;

break;

case 8 :cout<<“Eighteen”;

break;

case 9 :cout<<“Nineteen”;

break;

default:cout<<“Ten”;

break;

}

goto end;

case 2 :cout<<“Twenty “;

break;

case 3 :cout<<“Thirty “;

break;

case 4 :cout<<“Forty “;

break;

case 5 :cout<<“Fifty “;

break;

case 6 :cout<<“Sixty “;

break;

case 7 :cout<<“Seventy “;

break;

case 8 :cout<<“Eight “;

break;

case 9 :cout<<“Ninety “;

break;

default:cout<<“”;

break;

}

switch(o)

{

case 1 :cout<<“One”;

break;

case 2 :cout<<“Two”;

break;

case 3 :cout<<“Three”;

break;

case 4 :cout<<“Four”;

break;

case 5 :cout<<“Five”;

break;

case 6 :cout<<“Six”;

break;

case 7 :cout<<“Seven”;

break;

case 8 :cout<<“Eight”;

break;

case 9 :cout<<“Nine”;

break;

default:cout<<“”;

break;

}

end:

getch();

}

 

Q.18. WAP to find roots of quadratic equation

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{

clrscr();

float a,b,c;

cout<<“Enter the coefficients of x^2, x and constant:”;

cin>>a>>b>>c;

cout<<“Roots are:”<<((-1)*b+(sqrt(b*b-4*a*c)))/(2*a)<<“\n”<<((-1)*b-(sqrt(b*b-4*a*c)))/(2*a);

getch();

}

 

Q.19. WAP to print palindrome no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int a, p=0;

cout<<“Enter any number :”;

cin>>a;

for(;a>0;)

{

p=(p*10)+(a%10);

a=a/10;

}

cout<<“Palindrome is :”<<p;

getch();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s