Project 2

Programs to Continue reading

Advertisements

Project 1

Program 1

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,b, sum;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

sum = a+b;

cout <<“The sum of two numbers is “<<sum;

getch ();

}

 

Output:

Enter the first number: 23

Enter the second number: 31

The sum of two numbers is 54

 

 

 

 

 

Program 2

 

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,b,dif;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

dif=a-b;

cout <<“The difference of two numbers is: “<<dif;

getch ();

}

 

Output

Enter the first number: 21

Enter the second number: 14

The difference of two numbers is: 7

 

 

 

Program 3

 

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,b,prd;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

prd=a*b;

cout <<“The product of two numbers is “<<prd;

getch ();

}

 

Output

Enter the first number: 14

Enter the second number: 5

The product of two numbers is 70

 

 

 

 

 

Program 4

 

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,b,quot;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

quot=a/b;

cout <<“The quotient of two numbers is: “<<quot;

getch ();

}

 

Output

Enter the first number: 45

Enter the second number: 6

The quotient of two numbers is: 7.5.

 

Program 5

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,sqr;

cout <<“Enter a number: “;

cin >>a;

sqr=a*a;

cout <<“The square of “<<a<<” is “<<sqr;

getch ();

}

 

Output

Enter a number: 21

The square of 21 is 441

 

Program 6

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,b,ar,pmt;

cout <<“Enter the length of the rectangle: “;

cin >>a;

cout <<“Enter the breadth of the rectangle: “;

cin >>b;

ar=a*b;

pmt=2*(a+b);

cout <<“The area of the rectangle is “<<ar<<” and its perimeter is “<<pmt;

getch ();

}

 

Output

Enter the length of the rectangle: 7

Enter the breadth of the rectnagle: 6

The area of the rectangle is 42 and its perimeter is 26

 

Program 7

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float radius,area;

cout <<“Enter the radius of the circle is: “;

cin >>radius;

area=3.14*radius*radius;

cout <<“The Area of the circle is “<<area;

getch ();

}

Output

Enter the radius of the circle: 7

The Area of the circle is 153.86

 

Program 8

#include<iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int x,y,temp;

cout <<“Enter the value of x: “;

cin >>x;

cout <<“Enter the value of y: “;

cin >>y;

temp=x;

x=y;

y=temp;

cout <<“The value of x after swapping is: “<<x;

cout <<“\nThe value of y after swapping is: “<<y;

getch ();

}

Output

Enter the value of x: 45

Enter the value of y: 23

The value of x after swapping is: 23

The value of y after swapping is: 45

 

Program 9

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float p,r,t,sim;

cout <<“Enter the prinical amount of the loan: “;

cin >>p;

cout <<“Enter the rate of interest of the loan: “;

cin >>r;

cout <<“Enter the time period of the loan: “;

cin >>t;

sim = (p*r*t)/100;

cout <<“The simple interest on the loan is: “<<sim;

getch ();

}

 

 

Output

Enter the principal amount of the loan: 10000

Enter the rate of interest of the loan: 4.5

Enter the time period of the loan: 8

The simple interest on the loan is: 3600

 

Program 10

#include <iostream.h>

#include <conio.h>

#include <math.h>

void main ()

{

clrscr ();

float a,b,c,s,area;

cout <<“Enter the three sides of the triangle: “;

cin >>a>>b>>c;

s=(a+b+c)/2;

area=sqrt(s*(s-a)*(s-b)*(s-c));

cout <<“The area of the triangle is: “<<area;

getch ();

}

Output

Enter the three sides of the triangle: 12 23 34

The area of the triangle is: 66.8436

 

Program 11

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a,b,rem;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

rem = a%b;

cout <<“The remainder is: “<<rem;

getch ();

}

 

Program 12

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int num,f,s,l,temp;

cout <<“Enter a three digit number: “;

cin >>num;

f=num/100;

temp=num%100;

s=temp/10;

l=num%10;

cout <<“The first digit of the number is: “<<f<<“\n”;

cout <<“The second digit of the number is: “<<s<<“\n”;

cout <<“The third digit of the number is: “<<l<<“\n”;

int sum=f+s+l;

cout <<“The sum of the digits of numbers is: “<<sum;

getch();

}

 

 

Program 13

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

char ch;

int num;

cout <<“Enter a character: “;

cin>>ch;

num=ch;

cout <<“The ASCII Code of “<<ch<<” is “<<num;

getch ();

}

 

Program 14

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

char ch;

int num;

cout <<“Enter a ASCII code: “;

cin>>num;

ch=num;

cout <<“The character having to ASCII code “<<num<<” is “<<ch;

getch ();

}

 

Program 15

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a,b;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

if (a>b)

{

cout <<a<<” is greater than “<<b;

}

if (a<b)

{

cout <<a<<” is smaller than “<<b;

}

if (a==b)

{

cout <<a<<” is equal to “<<b;

}

getch ();

}

 

Program 16

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a,b;

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

if (a%b==0)

{

cout <<a<<” is divisible by “<<b;

}

else

{

cout <<a<<” is not divisible by “<<b;

}

getch ();

}

 

Program 17

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a;

cout <<“Enter a year: “;

cin >>a;

if (a%4==0)

{

cout <<a<<” is a leap year. “;

}

else

{

cout <<a<<” is not a leap year. “;

}

getch ();

}

 

Program 18

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int  choice;

float num1, num2;

cout <<“Choice 1: For Addition. \n”;

cout <<“Choice 2: For Subtraction. \n”;

cout <<“Choice 3: For Multiplication. \n”;

cout <<“Choice 4: For Division. \n”;

cout <<“Enter your choice: “;

cin >>choice;

cout <<“Enter the first number: “;

cin >>num1;

cout <<“Enter the second number: “;

cin >>num2;

if (choice==1)

{

cout <<“The sum of two numbers is: “<<num1+num2;

}

if (choice==2)

{

cout <<“The difference of two numbers is: “<<num1-num2;

}

if (choice==3)

{

cout <<“The product of two numbers is: “<<num1*num2;

}

if (choice==4)

{

cout <<“The quotient of two numbers is: “<<num1/num2;

}

getch ();

}

 

Program 19

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a,b,c;

cout <<“Enter the three numbers: “;

cin >>a>>b>>c;

if (a>b)

{

if (b>c)

{

cout <<a<<” is greater than “<<b<<” which is greater than “<<c<<“.”;

}

if (c>b && a>c)

{

cout <<a<<” Is greater than “<<c<<” which is greater than “<<b<<“.”;

}

}

if (b>a)

{

if (a>c)

{

cout <<b<<” is greater than “<<a<<” which is greater than “<<c<<“.”;

}

if (c>a && b>c)

{

cout <<b<<” is greater than “<<c<<” which is greater than “<<a<<“.”;

}

}

if (c>a)

{

if (a>b)

{

cout <<c<<” is greater than “<<a<<” which is greater than “<<b<<“.”;

}

if (b>a && c>b)

{

cout <<c<<” is greater than “<<b<<” which is greater than “<<a<<“.”;

}

}

getch ();

}

 

Program 20

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

char ch;

cout <<“Enter A Character: “;

cin>>ch;

if ((ch>=’A’ && ch<=’Z’) || (ch>=’a’ && ch<=’z’))

{

cout <<ch<<” is an Alphabetic character”;

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

{

cout <<” and it is an upper case letter. “;

}

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

{

cout <<” and it is a lower case letter. “;

}

else

{

cout <<ch<<” is not an Alphabetic character. “;

}

getch ();

}

 

Program 21

#include <iostream.h>

#include <conio.h>

#include <math.h>

void main ()

{

clrscr ();

float a,b,c,x,y,d;

cout <<“Enter the three coefficient of quadratic equation: “;

cin >>a>>b>>c;

if (a!=0)

{

cout <<“The quadratic equation is: “<<a<<“x^2 + “<<b<<“x + “<<c;

if (b*b-4*a*c>=0)

{

cout <<“\n””The roots of above quadratic equations are real: “;

x= (-b+sqrt(b*b-4*a*c))/2*a;

y= (-b-sqrt(b*b-4*a*c))/2*a;

cout <<“\n””The roots of the above quadratic equations are “<<x<<” and “<<y;

}

else

{

cout <<“\n””There are not real roots for the above quadratic equation. “;

}

}

else

{

cout <<“The above equation is not quadratic i.e. a is zero here  “;

}

getch ();

}

 

Program 22

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

float a,b,c,res;

int ch;

cout <<“Area Menu “”\n”;

cout <<“1. Circle “”\n”;

cout <<“2. Rectangle “”\n”;

cout <<“3. Triangle “”\n”;

cout <<“4. Trapezium “”\n”;

cout <<“\n””Enter Your Choice: “;

cin >>ch;

switch (ch)

{

case 1: cout <<“Enter the radius: “;

cin>>a;

cout <<“The Area of the circle is: “<<3.14*a*a;

break;

case 2: cout <<“Enter the length: “;

cin>>a;

cout <<“Enter the breadth: “;

cin>>b;

cout <<“The Area of the Rectangle is: “<<a*b;

break;

case 3: cout <<“Enter the base length: “;

cin >>a;

cout <<“Enter the altitude: “;

cin >>b;

cout <<“The Area of the Triangle is: “<<0.5*a*b;

break;

case 4: cout<< “Enter the height: ” ;

cin >>a;

cout <<“Enter the parallel sides: “;

cin>>b>>c;

cout <<“The Area of the trapezium is: “<<0.5*a*(b+c);

break;

default: cout <<“Wrong Choice. “;

break;

}

getch ();

}

 

Program 23

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int ch;

float x,y;

cout <<“Choice 1: Fahrenheit to Celsius. “”\n”;

cout <<“Choice 2: Celsius to Fahrenheit. “”\n”;

cout <<“\n””Enter Your Choice: “;

cin >>ch;

switch (ch)

{

case 1: cout <<“Enter the temperature in degree fahrenheit: “;

cin >>x;

y=(x-32)*5/9;

cout <<“The corresponding temperature in degree celsius is: “<<y;

break;

case 2: cout <<“Enter the temperature in degree celsius: “;

cin >>x;

y=(9*x)/5+32;

cout <<“The corresponding temperature in degree fahrenheit is: “<<y;

break;

default : cout <<“Wrong Choice. “;

break;

}

getch ();

}

 

Program 24

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int x;

for (x=1;x<=20;x++)

{

cout <<x<<” “;

}

getch ();

}

 

Program 25

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int x;

for (x=20;x>=1;x–)

{

cout <<x<<” “;

}

getch ();

}

 

Program 26

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int x,y;

for (x=1;x<=25;x++)

{

y=2*x-1;

cout <<y<<” “;

}

getch();

}

 

Program 27

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int r,x,sum=0;

cout <<“Enter the range: “;

cin >>r;

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

{

sum=sum+x;

}

cout <<“The sum of numbers up to”<<r<<” is: “<<sum;

getch ();

}

 

Program 28

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a=-1,b=1,c,ctr,r,sum=0;

cout <<“Enter the range: “;

cin >>r;

cout <<“The fibonacci series upto “<<r<<“th term is: \n”;

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

{

c=a+b;

a=b;

b=c;

cout <<c<<” “;

sum = sum+c;

}

cout <<“\nThe sum of terms of fibonacci series upto “<<r<<“th term is: “<<sum;

getch ();

}

 

 

 

Program 29

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int r,x,d=2;

cout<<“Enter the range: “;

cin >>r;

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

{

d=d-x;

}

cout <<“The difference of natural number upto “<<r<<” is “<<d;

getch();

}

 

Program 30

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int r,x=1,s0=0,s1=0;

cout <<“Enter the range: “;

cin >>r;

while (x<=r)

{

if (x%2==0)

{

s0=s0+x;

}

else

{

s1=s1+x;

}

x++;

}

cout <<“The sum of all odd number up to “<<r<<” is “<<s1;

cout <<“\n””The sum of all even number up to “<<r<<” is “<<s0;

getch ();

}

 

Program 31

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int x=1,b,e;

long int p=1;

cout <<“Enter the base number: “;

cin >>b;

cout <<“Enter the exponent: “;

cin>>e;

while (x<=e)

{

p=p*b;

x++;

}

cout <<b<<” to the power “<<e<<” is “<<p;

getch ();

}

 

Program 32

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr ();

long int n,fact=1,x;

cout <<“Enter the number: “;

cin >>n;

x=n;

while (x>=1)

{

fact=fact*x;

x–;

}

cout <<“The factorial of “<<n<<” is “<<fact;

getch ();

}

 

Program 33

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a,b,x,temp;

cout <<“Enter the two numbers “;

cin >>a>>b;

int y=a;

int z=b;

while (a%b!=0)

{

temp=b;

b=a%b;

a=temp;

}

cout <<“The HCF of “<<y<<” and “<<z<<” is “<<b;

getch();

}

 

Program 34

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int n,x=2,c=2;

cout <<“Enter a number: “;

cin >>n;

while (n%x!=0)

{

c++;

x++;

}

if (c==n)

{

cout <<n<<” is a prime number. “;

}

else

{

cout <<n<<” is not a prime number. “;

}

getch ();

}

 

Program 35

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a,b;

char ch;

do

{

cout <<“Enter the first number: “;

cin >>a;

cout <<“Enter the second number: “;

cin >>b;

cout <<“The sum of two numbers is: “<<a+b;

cout <<“\nDo you Want to continue: “;

cin >>ch;

if (ch==’y’ || ch==’Y’)

{

cout <<“Go again.\n”;

}

else

{

cout <<“Press Enter to exit \n”;

}

} while(ch==’y’ || ch==’Y’);

getch ();

}

Program 36

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int x,y;

char ch;

cout <<“Enter a number: “;

cin >>x;

y=x;

do

{

cout <<“Do you want to enter another number: “;

cin >>ch;

if (ch==’y’ || ch==’Y’)

{

cout <<“Enter another number: “;

cin >>x;

if (x>y)

{

y=x;

}

} }while (ch==’y’ || ch==’Y’);

cout <<“The maximum of the entered number is: “<<y;

getch ();

}

 

Program 37

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int n,sum=0,m;

cout <<“Enter a number: “;

cin >>n;

int x=n;

do

{

m=n%10;

sum=sum+m;

n=n/10;

} while (n!=0);

cout <<“The sum of the digits of “<<x<<” is “<<sum;

getch ();

}

 

 

Program 38

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int n,m,rev=0,i;

cout <<“Enter a range: “;

cin >>n;

i=n;

do

{

m=n%10;

rev=rev*10+m;

n=n/10;

}while (n!=0);

if (rev==i)

{

cout <<“The no. is a palindrome. “;

}

else

{

cout <<“The no. is not a palindrome. “;

}

getch ();

}

Program 39

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int i,j;

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

{

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

{

cout <<“$ “;

}

cout <<“\n”;

}

getch ();

}

 

Program 40

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int i,j;

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

{

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

{

cout <<j<<” “;

}

cout <<“\n”;

}

getch ();

}

 

Program 41

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

long int a,b[50];

cout <<“Enter A Number: “;

cin >>a;

int i=0,j;

cout <<“The Binary of “<<a<<” is “;

do

{

b[i]=a%2;

i++;

a=a/2;

} while (a/2!=0);

cout <<a;

for (j=i-1;j>=0;j–)

{

cout <<b[j];

}

getch ();

}

 

Program 42

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int r,x,i,m,c;

cout <<“Enter the range: “;

cin >>r;

cout <<“The Armstrong number upto the given range are: “;

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

{

x=i,c=0;

do

{

m=x%10;

c=c+m*m*m;

x=x/10;

}while (x!=0);

if (i==c)

{

cout <<c<<” “;

}

}

getch ();

}

 

Program 43

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int r,i,c,x;

cout <<“Enter the range: “;

cin>>r;

cout <<“The prime number up to “<<r<<” is: \n”;

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

{

x=2;

c=2;

while (i%x!=0)

{

x++;

c++;

}

if (c==i)

{

cout <<c<<”  “;

}

}

getch ();

}

 

Program 44

#include <iostream.h>

#include <conio.h>

float sum(float m,float n);

void main ()

{

clrscr ();

float a,b;

cout <<“Enter the two number: “;

cin >>a>>b;

cout <<“The sum of the two numbers is: “;

sum(a,b);

getch ();

}

float sum(float x,float y)

{

cout <<x+y;

}

 

Program 45

#include <iostream.h>

#include <conio.h>

float cube(float no);

void main ()

{

clrscr ();

float num;

cout <<“Enter a number: “;

cin >>num;

cout <<“The cube of “<<num<<” is “;

cube(num);

getch ();

}

float cube(float x)

{

cout <<x*x*x;

}

 

Program 46

#include <iostream.h>

#include <conio.h>

int swap(int& m, int& n);

void main ()

{

clrscr ();

int a,b;

cout <<“Enter the value of a: “;

cin >>a;

cout <<“Enter the value of b: “;

cin >>b;

swap (a,b);

cout <<“After swapping the value of a: “<<a<<” and b: “<<b;

getch ();

}

int swap(int &x, int&y)

{

int temp;

temp =x;

x=y;

y=temp;

}

 

Program 47

 

#include <iostream.h>

#include <conio.h>

#include <math.h>

void main ()

{

clrscr ();

float a,sqt;

cout <<“Enter a number: “;

cin >>a;

sqt=sqrt(a);

cout <<“The square root of “<<a<<” is “<<sqt;

getch ();

}

 

Output

Enter a number: 196

The square root of 196 is 14

 

Program 48

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr ();

int a;

cout <<“ENTER NUMBER OF WEEK’S DAY (1-7): “<<\n<<”THE  DAY IS”;

cin >>a;

switch (a)

{

case 1: cout<<“IT IS MONDAY”;

break;

case 2: cout <<“IT IS TUESDAY”;

break;

case 3: cout <<“IT IS WEDNESDAY”;

break;

case 4:cout <<“IT IS THRUSDAY”;

break;

case 5:cout <<“IT IS FRIDAY”;

break;

case 6:cout <<“IT IS SATURDAY”;

break;

case 7:cout <<“IT IS SUNDAY”;

break;

default: cout <<“WRONG NUMBER OF DAY “;

break;

}

getch ();

}

OUTPUT

ENTER THE OF WEEK’S DAY(1-7)= 2

AND THE IS =  Tuesday

 

 

 

 

 

 

 

 

 

Structure

WAP to find annual income of employee.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

const int size=5;

float Sal[size],sal;

int count=0;

for(int i=0;i<size;i++)

{

cout<<“Enter the monthly salary of employee:”<<i+1<<“\n”;

cin>>Sal[i];

}

for(i=0;i<size;i++)

{

sal=Sal[i]*12;

if(sal>100000)

count++;

}

cout<<count<<” Employee out of “<<size<<” employee are earning more than Rs. 1 Lakh per annum.”;

getch();

}

WAP to find the concanated string.

#include<iostream.h>

#include<conio.h>

#include<string.h>

 

void main()

{

clrscr();

char str1[25],str2[25],str3[50];

int i,j,x,k;

cout<<“Enter the first string:”;

cin.getline(str1,25);

cout<<“Enter the second string:”;

cin.getline(str2,25);

for(i=0;str1[i]!=’\0′;++i)

str3[i]=str1[i];

for(k=0;str2[k]!=’\0′;++k)

str3[i+k]=str2[k];

str3[i+k]=’\0′;

x=strlen(str3);

cout<<“The concatenated string is:”;

cout.write(str3,x);

getch();

}

WAP to delete a string.

 

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char str[100];

int i,p,n,len;

cout<<“Enter the string:”;

gets(str);

for(len=0;str[len]!=’\0′;++len);

cout<<“Enter the starting position of substring to be deleted:”;

cin>>p;

if(p>len)

cout<<“Starting position must be less than the length of the  String.Abortng!!!”;

{

cout<<“Enter the number of charaters of substring to be deleted :”;

cin>>n;

if(n+p>=len)

n=len-p+1;

for(i=p-1;str[i]!=’\0′;++i)

str[i]=str[i+n];

cout<<“String after del. string is:”<<str;

}

getch();

}

 

 

 

 

 

 

 

 

 

WAP to find that a string is pallindrome or not.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char str[100],c;

cout<<“Enter the string:”;

cin.getline(str,100);

for(int len=0;str[len]!=’\0′;len++);

int i,j,f=1;

for(i=0,j=len-1;i<len/2;i++,j–)

{

if(str[i]!=str[j])

{

f=0;

break;

}}

if(f!=0)

cout<<“It’s a pallindrome.”;

else

cout<<“It’s not a pallindrome.”;

getch();

}

WAP  to accept the marks of student and print the marks.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

const int size=5;

float marks[size];

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

{

cout<<“Enter the marks of student [“<<i<<“]:”;

cin>>marks[i];

}

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

cout<<“Marks of student [“<<i<<“]=”<<marks[i]<<“\n”;

getch();

}

 

 

WAP to print a string in reverse order.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char str[100];

int i,j,k;

cout<<“Enter any string:”;

gets(str);

for(i=0;str[i]!=’\0′;++i);

char rev[100];

for(j=i-1,k=0;j>=0;–j,++k)

rev[k]=str[j];

rev[k]=’\0′;

cout<<“The string in reverse order:”;

puts(rev);

getch();

}

WAP to print the total sales and average sales.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

const int size=5;

float sales[size],avg=0,total=0;

for(int i=0;i<size;i++)

{

cout<<“Enter the sales of day:”<<i+1<<“\n”;

cin>>sales[i];

total+=sales[i];

}

avg=total/size;

cout<<“\nTotal sales=”<<total<<“\n”;

cout<<“Average sales=”<<avg<<“\n”;

getch();

}

 

WAP to find the total number of vowels.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char line[100];

int i,v=0;

cout<<“Enter the line:”;

gets(line);

for(i=0;line[i]!=’\0′;i++)

{

switch(line[i])

{

case ‘a’:

case ‘e’:

case ‘i’:

case ‘o’:

case ‘u’:

case ‘A’:

case ‘E’:

case ‘I’:

case ‘O’:

case ‘U’:

v++;

}

}

cout<<“The total number of vowels are:”<<v;

getch();

}

 

 

 

 

 

WAP to print the employee information.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

struct emp

{

int empno;

char name[20];

float pay;

};

emp inf;

void main()

{

clrscr();

cout<<“Enter the employee ID:”;

cin>>inf.empno;

cout<<“Enter the employee name:”;

gets(inf.name);

cout<<“Enter the basic pay of employee:”;

cin>>inf.pay;

{

cout<<“\n”<<“Employee information-“<<“\n”;

cout<<“\n”;

cout<<“The employee ID is:”<<inf.empno<<“\n”;

cout<<“The employee name is:”;

cout.write(inf.name,20)<<“\n”;

cout<<“The employee basic pay is:”<<inf.pay<<“\n”;

getch();

}

}

 

 

 

 

 

 

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();

}

 

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();

}

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();

}

 

 

 

 

 

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();

}

 

 

 

. 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      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();

}

 

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();

}

 

Program of Book Entry Using structure Variable.

 

#include<iostream.h>

#include<stdio.h>

struct books

{

char name[20],author[20];

}a[50];

int main()

{

int i,n;

cout<<“No Of Books[less than 50]:”;

cin>>n;

cout<<“Enter the book details\n”;

cout<<“———————-\n”;

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

{

cout<<“Details of Book No “<<i+1<<“\n”;

cout<<“Book Name :”;

cin>>a[i].name;

cout<<“Book Author :”;

cin>>a[i].author;

cout<<“———————-\n”;

}

cout<<“================================================\n”;

cout<<” S.No\t| Book Name\t|author\n”;

cout<<“=====================================================”;

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

{

cout<<“\n  “<<i+1<<“\t|”<<a[i].name<<“\t| “<<a[i].author;

}

cout<<“\n=================================================”;

return 0;

}

 

WAP to enter a letter and output the next 2 letters.

 

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

char charac;

cout <<“Enter your letter : “<< endl;

cin>>charac;

cout <<“The 2 letters are : “<< endl;

cout << (char)(charac-1) << endl;

cout << (char)(charac+1) << endl;

getch();

}

 

 

 

WAP to identify if an input is a symbol, digit or character.

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

char charac;

cout <<“Enter your input : “<< endl;

cin>>charac;

if(((charac>=’A’)&&(charac<=’Z’))||((charac>=’a’)&&(charac<=’z’)))

cout <<“Your input “<< charac <<” is a character.”<< endl;

else if((charac>=’0′)&&(charac<=’9′))

cout <<“Your input “<< charac <<” is a digit.”<< endl;

else

cout <<“Your input “<< charac <<” is a symbol.”<< endl;

getch();

}

 

 

WAP to find the total days in the year till date.

 

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int day,month,total;

int days_per_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

cout <<“Enter the month : “<< endl;

cin>>month;

cout <<“Enter the day : “<< endl;

cin>>day;

total=day;

for(int x=0;x<month-1;x++)

total+=days_per_month[x];

cout <<“The number of days in this year till date = “<< total << endl;

getch();

}

WAP to convert days into years and weeks.

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int days,years,weeks,num1;

cout <<“Enter the number of days : “<< endl;

cin>>days;

years=days/365;

num1=days-(years*365);

weeks=days/7;

num1=days-(weeks*7);

cout << days <<” days = “<< endl;

cout << weeks <<” weeks OR “<< endl;

cout << years <<” years.”<< endl;

getch();

}

 

WAP to convert 2-digit octal number into binary number and print it.

#include <iostream.h>

#include <conio.h>

void octobin(int);

void main()

{

clrscr();

int a;

cout <<“Enter a 2-digit octal number : “;

cin>>a;

octobin(a);

getch();

}

void octobin(int oct)

{

long bnum=0;

int A[6];

int a1,a2,quo,rem;

a2=oct/10;

a1=oct-a2*10;

for(int x=0;x<6;x++)

{

A[x]=0;

}

for (x=0;x<3;x++)

{

quo=a1/2;

rem=a1%2;

A[x]=rem;

a1=quo;

}

for(x=3;x<6;x++)

{

quo=a2/2;

rem=a2%2;

A[x]=rem;

a2=quo;

}

for(x=x-1;x>=0;x–)

{

bnum*=10;

bnum+=A[x];

}

cout <<“The binary number for the octal number “<< oct <<” is “<< bnum <<“.”<< endl;

}

Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the  diagonals also.

#include <iostream.h>

#include <conio.h>

int main()

{clrscr();

int A[10][10],m,n,x,y,sum=0;

cout <<“Enter number of rows and columns in Matrix A : \n”;

cin>>n>>m;

cout <<“Enter elements of Matrix A : \n”;

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

for(y=1;y<m+1;++y)

cin>>A[x][y];

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

{A[x][m+1]=0;

for(y=1;y<m+1;++y)

A[x][m+1]=A[x][m+1]+A[x][y];}

for(y=1;y<m+1;++y)

{A[n+1][y]=0;

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

A[n+1][y]+=A[x][y];

}cout <<“\nMatrix A, Row Sum (Last Column)”<<” and Column Sum (Last Row) : \n”;

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

{for(y=1;y<m+2;++y)

cout << A[x][y] <<“”;

cout <<“\n”;}

x=n+1;

for(y=1;y<m+1;++y)

cout << A[x][y] <<“”;

cout <<“\n”;

if(m==n)

{for(x=1;x<m+1;x++)

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

if(x==y)

sum+=A[x][y];

else

if(y==m-(x+1))

sum+=A[x][y];}

cout <<“Sum of diagonal elements is : “<< sum << endl;

getch();

return 0;}

Program to enter an integer and print its total value based on the formula

‘x – 1/3!x^3 + 1/5!x^5 – 1/7!x^7 + 1/9!x^9′

 

#include <iostream.h>

#include <conio.h>

#include <math.h>

int main()

{ clrscr();

float factorial=1;

float num,tot,term,total;

int i,n=20,index,j=1;

cout <<“Enter a single-digit integer : \n”;

cin>>num;

tot=num;

total=num;

for(i=2,index=3;i<=n;i++,index+=2)

{ for(j=1,factorial=1;j<=index;j++)

factorial*=j;

tot=tot*pow((double)(-1),(double)(2*i-1))*num*num;

term=tot/factorial;

total+=term;}

cout <<“Total = “<< total << endl;

getch();

return 0;

}

 

Program to enter an integer and output it in the reversed form

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

long int num1,num2,rnum=0;

cout <<“Enter an integer : “<< endl;

cin>>num1;

num2=num1;

do

{

rnum=rnum*10;

int digit=num1%10;

rnum+=digit;

num1/=10;

}

while(num1);

cout <<“The integer you typed is “<< num2 <<“.”<< endl;

cout <<“The reversed integer is “<< rnum <<“.”<< endl;

getch();

}

 

Program to find the roots of a quadratic equation

#include <iostream.h>

#include <conio.h>

#include <math.h>

int main()

{

clrscr();

float a,b,c,d,root1,root2;

cout <<“Enter the 3 coefficients a, b, c : “<< endl;

cin>>a>>b>>c;

if(!a){

if(!b)

cout <<“Both a and b cannot be 0 in ax^2 + bx + c = 0″<<“\n”;

else

{

d=-c/b;

cout <<“The solution of the linear equation is : “<< d << endl;

}}

else

{

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

if(d>0)

root1=(-b+sqrt(d))/(2*a);

root2=(-b-sqrt(d))/(2*a);

cout <<“The first root = “<< root1 << endl;

cout <<“The second root = “<< root2 << endl;

}

getch();

return 0;

}

Program to enter salary and output income tax and net salary

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int itrate;

float salary,itax,nsalary=0;

cout <<“Enter the salary : “;

cin>>salary;

if(salary>15000)

{

itax=salary*30/100;

itrate=30;

}

else if(salary>=7000)

{

itax=salary*20/100;

itrate=20;

}

else

{

itax=salary*10/100;

itrate=10;

}

nsalary=salary-itax;

cout <<“Salary = $”<< salary << endl;

cout <<“Your income tax @ “<< itrate <<“% = $”<< itax << endl;

cout <<“Your net salary = $”<< nsalary << endl;

getch();

}

Program to count the number of words and characters in a sentence

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int countch=0;

int countwd=1;

cout <<“Enter your sentence in lowercase: “<< endl;

char ch=’a’;

while(ch!=’\r’)

{

ch=getche();

if(ch==”)

countwd++;

else

countch++;

}

cout <<“\n Words = “<< countwd << endl;

cout <<“Characters = “<< countch-1 << endl;

getch();

}

Program to enter the unit reading and output the customer’s telephone bill

#include <iostream.h>

#include <conio.h>

int main()

{

clrscr();

long int units,charge=0;

float total;

const int rent=25;

cout <<“Enter the number of units used : “;

cin>>units;

if(units>200)

charge=(units-200)*20+150*40+50*60;

else if(units>50)

charge=(units-50)*40+50*60;

else

charge=units*60;

total=0.01*charge+rent;

cout <<“You have used “<< units <<” units.”<< endl;

cout <<“Your total telephone bill is $”<< total;

getch();

return 0;

}

Program to enter a string and find its length

#include <iostream.h>

#include <conio.h>

#include <string.h>

void main()

{

clrscr();

int slength;

char x[81]; //Allowing the user to input a maximum of 80 characters.

cout <<“Enter the string : “<< endl;

cin>>x;

slength=strlen(x);

cout <<“The length of the string “<< x <<” is “<< slength <<“.”<< endl;

getch();

}

 

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();

}