45 interestintg programs

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   
   
   






               -X-X-X-X-X-X-X The EndX-X-X-X-X-X-X-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   
   
   





               -X-X-X-X-X-X-X The EndX-X-X-X-X-X-X-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   
   
   





                

Comments

Popular Posts