0% found this document useful (0 votes)
19 views16 pages

Pgrogram 1

Uploaded by

morbiusx777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views16 pages

Pgrogram 1

Uploaded by

morbiusx777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Program : Write program in C++ to find bigest number among three numbers using

nesting if else stattement.

//to find out greater number among three numbers

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<“enter a,b and c numbers”;
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<“ a is greater “<<a;
else
cout<<“ c is greater “<<c;
}
else
{
if(b>c)
cout<<“ b is greater “<<b;
else
cout<<“ c is greater “<<c;
}
getch();
}

Output :

Enter a,b and c numbers 10 20 30


c is greater 30
Program : Write program in C++ to find smllest number among three numbers using
conditinal operator.
// smallest number using conditional operator

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,t,small;
cout<<“Enter two numbers”<<endl;
cin>>a>>b>>c;
t=(a<b)?a:b;
small=(c<t)?c:t;
cout<<“Smallest number is “<<small;
getch();
}

Output:
Enter two numbers
10 90 6
Smallest number is 6
Program : Write program in C++ to enter a percentage of a student display grade as
per the following table using if else ladder.
// if else ladder

#include<iostream.h>
#include<conio.h>
void main()
{
int e,m,h,ma,s,so,T,per;
cout<<“Enter the marks of five subjects”<<endl;
cin>>e>>m>>h>>ma>>s>>so;
T=e+m+h+ma+s+so;
per=T/6;
cout<<“Total of marks”<<T<<endl;
cout<<“Percntage of students is”<<per<<endl;
if(per>=75)
cout<<“Honors”<<per<<endl;
else if(per>=60)
cout<<“First Class”<<per<<endl;
else if(per>=45)
cout<<“Second Class”<<per<<endl;
else if(per>=35)
cout<<“Third Class”<<per<<endl;
else
cout<<“Fail”;
getch();
}
Program : Write program in C++ to enter a number of month and display name of the
month using switch staterment.
//Switch program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<“Enter a number”<<endl;
cin>>n;
switch(n)
{
case 1:
{
cout<<“January”;
break;
}
case 2:
{
cout<<“February”;
break;
}
case 3:
{
cout<<“March”;
break;
}
case 4:
{
cout<<“April”;
break;
}
case 5:
{
cout<<“May”;
break;
}
case 6:
{
cout<<“June”;
break;
}
case 7:
{
cout<<“July”;
break;
}
case 7:
{
cout<<“July”;
break;
}
case 8:
{
cout<<“August”;
break;
}
case 9:
{
cout<<“September”;
break;
}
case 10:
{
cout<<“October”;
break;
}
case 11:
{
cout<<“November”;
break;
}
case 12:
{
cout<<“December”;
break;
}
}
getch();
}

Output:
Enter a number
10
October
Program : Write program in C++ to interchange (swap) two values without using
third variable.
//exchange the conents of two variable without using third variable

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<“enter two numbers”;
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<“After exchange “<<endl<<a<<“\t”<<b;
getch();
}

Output :
enter two numbers100 200
After exchange
200 100
Program : Write program in C++ to check weather a given integer number is
pallindrome or not.
//number is pallindrome

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c=0,d;
cout<<“Enter number”<<endl;
cin>>a;
b=a;
while(b!=0)
{
d=b%10;
c=(c*10)+d;
b=b/10;
}
if(a==c)
cout<<“The number is pallindrome”<<a;
else
cout<<“The number is not pallindrome”<<a;
getch();
}

Output:
Enter number
333
The number is pallindrome333
Program : Write program in C++ to check weather a given integer number is
amstrong ot not.

//amstrong number

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<“Enter a number”<<endl;
cin>>a;
b=a;
c=0;
while(b!=0)
{
d=b%10;
c=c+(d*d*d);
b=b/10;
}
if(a==c)
cout<<“The number is amstrong number”<<a;
else
cout<<“The number is not amstrong”<<a;
getch();
}

Output:
Enter a number
1
The number is amstrong number1
Program : Write program in C++ to enter a integer number and calculate sum of
digits. ( Ex No 12345 = 1+2+3+4+5 = 15)
//sum of digit

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,sum=0;
cout<<“Enter number”<<endl;
cin>>a;
b=a;
while(b!=0)
{
sum=sum+b%10;
b=b/10;
}
cout<<“The sum of digit is”<<sum;
getch();
}

Output :
Enter number
12345
The sum of digit is15
Program : Write program in C++ to display Fibinocci series of 15 terms.

//fibinocii series of 15 terms

# include<iostream.h>
# include<conio.h>
void main ()
{
clrscr ();
int a=0,b=1,i=3,c;
cout <<a<<“\t”<<b<<“\t”;
while (i<=15)
{
c=a+b;
cout <<c<<“\t”;
a=b;
b=c;
i++;
}
getch ();
}

Output :
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Program : Write program in C++ to calculate and print factorial of first 10 numbers.

// Factrial of first 10 numbers

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int count,fact=1;
for(count=1;count<=10;count++)
{
fact=fact*count;
}
cout<<“factorial of first 10 nos.”<<fact;
getch();
}

Output:
factorial of first 10 nos.3628800
Program : Write program in C++ to accept a number and test weather it is prime or
not.
//Number is prime or not

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int p,c=0,i;
cout<<“Enter a number”<<endl;
cin>>p;
for(i=2;i<p;i++)
{
if(p%i==0)
c=1;
}
if(c==0)
cout<<“Number is prime”<<p;
else
cout<<“Number is not prime”<<p;
getch();
}

Output:
Enter a number
6
Number is not prime6
Program : Write program in C++ to print and calculate sum of first 10 natural
numbers.

// Sum of first 10 natural numbers

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int count,sum=0;
for(count=1;count<=10;count++)
{
sum=sum+count;
}
cout<<“sum of first 10 numbers”<<endl<<sum;
getch();
}

Output :
sum of first 10 numbers
55
Program : Write program in C++ to enter two integer numbers and find out GCD and
LCM.

//To find GCD and LCM of given numbers

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,x,l;
cout<<“Enter two numbers”<<endl;
cin>>a>>b;
x=a*b;
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
l=x/a;
cout<<“The GCD of numbers is “<<a<<endl;
cout<<“The LCM of numbers is “<<l;
getch();
}

Output :
Enter two numbers
25 15
The GCD of numbers is 5
The LCM of numbers is 75
Program : Write program in C++ to calculate the area of circle using function.
//Area of circle using function

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
void area();
area();
getch();
}

void area()
{
int a,r;
cout<<“Enter radius of circle”;
cin>>r;
a=3.14*r*r;
cout<<“Area of circle is “<<a<<endl;
}

Output :
Enter radius of circle2
Area of circle is 12
Program : Write program in C++ to swap values of two variables using pass by
reference fdunction

// Swap values of two variables using call by reference function.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
void add(int &a, int &b);
cout<<“Enter two number for addition”;
cin>>a>>b;
add(a,b);
getch();
}

void add(int &x,int &y)


{
int c;
c=x;
x=y;
y=c;
cout<<“After swapping “<<endl<<x<<“\t”<<y;
}

output :
Enter two number for addition100 200
After swapping
200 100

You might also like