#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int i,j,temp,n;
cout<<"Enter the size of array";
cin>>n;
int a[n];
cout<<"Enter the elements of array"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]<a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;}
}
}cout<<"Array in ascending order"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
getch();
}
i"ll try to upload all the c++ programs which i have done::::: if there is mistake tell me in comments....
Thursday, 24 December 2015
Tuesday, 22 December 2015
WRITE A PROGRAM THAT INPUT AN ARRAY OF 10 INTEGERS AND TELLS HOW MANY PROME NUMBERS ARE THERE IN THIS ARRAY.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int num,p=0,count=0;
int array[10]={1,2,3,4,5,6,7,8,9,10};
for(int a=0; a<10; a++)
{
for(int c=2;c<=array[a]/2;c++)
{if(array[a]%c==1)
{
p=1;
break;}}
if(p==0)
count++;}
cout<<"PRIME NUMBERS IN ARRAY ARE "<<count;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ int num,p=0,count=0;
int array[10]={1,2,3,4,5,6,7,8,9,10};
for(int a=0; a<10; a++)
{
for(int c=2;c<=array[a]/2;c++)
{if(array[a]%c==1)
{
p=1;
break;}}
if(p==0)
count++;}
cout<<"PRIME NUMBERS IN ARRAY ARE "<<count;
getch();
}
Tuesday, 15 December 2015
Write a program that intialize an array of 10 elements and input a integer from user to be searched...using binery search
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int arr[10]={10,20,30,40,50,60,70,80,90,100};
int mid,start,end,loc,n;
start=0;
end=9;
loc=-1;
cout<<"Enter element to be search ";
cin>>n;
while(start<=end)
{
mid=(start+end)/2;
if(n==arr[mid])
{
loc=mid;
break;}
else if(n<arr[mid])
end=mid-1;
else
start=mid+1;}
if(loc==-1)
cout<<"Element not found ";
else
cout<<"Element found at "<<loc;
getch();
}
#include<conio.h>
using namespace std;
main()
{
int arr[10]={10,20,30,40,50,60,70,80,90,100};
int mid,start,end,loc,n;
start=0;
end=9;
loc=-1;
cout<<"Enter element to be search ";
cin>>n;
while(start<=end)
{
mid=(start+end)/2;
if(n==arr[mid])
{
loc=mid;
break;}
else if(n<arr[mid])
end=mid-1;
else
start=mid+1;}
if(loc==-1)
cout<<"Element not found ";
else
cout<<"Element found at "<<loc;
getch();
}
Write a program that declare an array of 10 elements and input an element n to be searched,,with sequential search
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int arr[10]={10,20,30,40,50,60,70,80,90,100};
int n, loc=-1;
cout<<"Enter element to be search ";
cin>>n;
for(int a=0; a<n; a++)
{
if(n=arr[a])
loc=a;}
if(loc==-1)
cout<<" VAlue not found";
else
cout<<" Value found at array "<<loc;
}
#include<conio.h>
using namespace std;
main()
{
int arr[10]={10,20,30,40,50,60,70,80,90,100};
int n, loc=-1;
cout<<"Enter element to be search ";
cin>>n;
for(int a=0; a<n; a++)
{
if(n=arr[a])
loc=a;}
if(loc==-1)
cout<<" VAlue not found";
else
cout<<" Value found at array "<<loc;
}
Monday, 14 December 2015
Write a program that input two numbers and multiply them using a function
#include<iostream>
#include<conio.h>
using namespace std;
int mul(int x,int y)
{
return(x*y);
}
main()
{ int a,b;
cout<<"Enter two numbers to multiply"<<endl;
cin>>a>>b;
int res1=mul(a,b);
cout<<"product is "<<res1;
getch();
}
#include<conio.h>
using namespace std;
int mul(int x,int y)
{
return(x*y);
}
main()
{ int a,b;
cout<<"Enter two numbers to multiply"<<endl;
cin>>a>>b;
int res1=mul(a,b);
cout<<"product is "<<res1;
getch();
}
write a program that input two numbers and add them using a function
#include<iostream>
#include<conio.h>
using namespace std;
int sum(int x,int y)
{
return(x+y);
}
main()
{ int a,b;
cout<<"Enter two numbers to add"<<endl;
cin>>a>>b;
int res1=sum(a,b);
cout<<"Sum is "<<res1;
getch();
}
#include<conio.h>
using namespace std;
int sum(int x,int y)
{
return(x+y);
}
main()
{ int a,b;
cout<<"Enter two numbers to add"<<endl;
cin>>a>>b;
int res1=sum(a,b);
cout<<"Sum is "<<res1;
getch();
}
Saturday, 12 December 2015
WRITE A program that input the name and marks of students of BSCS/IT and dispaly the name of student who got highest marks and show lowest marks with name of student
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int max,min,roll1,roll2,n;
cout<<"enter strength of class BSCS/IT = ";
cin>>n;
int marks[n],roll[n];
string name[n],name1,name2;
for(int a=0;a<n;a++)
{ cout<<"enter roll number = "<<endl;
cin>>roll[a];
cout<<"enter name of roll number "<<endl;
cin>>name[a];
cout<<"Enter marks of student"<<endl;
cin>>marks[a];
max=min=marks[a];}
for(int a=0;a<n;a++)
{
if(max<marks[a])
{
max=marks[a];
name2=name[a];
roll2=roll[a];}
if(min>marks[a])
{
min=marks[a];
name1=name[a];
roll1=roll[a];}
}
cout<<name2<<" roll number "<<roll2<<" got maximum marks = "<<max<<endl;
cout<<name1<<" roll number "<<roll1<<" got minimum marks = "<<min;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ int max,min,roll1,roll2,n;
cout<<"enter strength of class BSCS/IT = ";
cin>>n;
int marks[n],roll[n];
string name[n],name1,name2;
for(int a=0;a<n;a++)
{ cout<<"enter roll number = "<<endl;
cin>>roll[a];
cout<<"enter name of roll number "<<endl;
cin>>name[a];
cout<<"Enter marks of student"<<endl;
cin>>marks[a];
max=min=marks[a];}
for(int a=0;a<n;a++)
{
if(max<marks[a])
{
max=marks[a];
name2=name[a];
roll2=roll[a];}
if(min>marks[a])
{
min=marks[a];
name1=name[a];
roll1=roll[a];}
}
cout<<name2<<" roll number "<<roll2<<" got maximum marks = "<<max<<endl;
cout<<name1<<" roll number "<<roll1<<" got minimum marks = "<<min;
getch();
}
write a program that input the x,y coordinates for two points and compute the distance between two points using formula Distance= sqrt[(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)]
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{ float x1,y1,x2,y2,d;
cout<<"Enter coordinates (x1,y1)"<<endl;
cin>>x1>>y1;
cout<<"Enter coordinates (x2,y2)"<<endl;
cin>>x2>>y2;
d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
cout<<"distance is = "<<d;
getch();
}
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{ float x1,y1,x2,y2,d;
cout<<"Enter coordinates (x1,y1)"<<endl;
cin>>x1>>y1;
cout<<"Enter coordinates (x2,y2)"<<endl;
cin>>x2>>y2;
d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
cout<<"distance is = "<<d;
getch();
}
write a program to calculate the volume(v) of a cube by taking measures fro user (formula: v=length*width*height)
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ float length,width,height,volume;
cout<<"Enter length"<<endl;
cin>>length;
cout<<"Enter width"<<endl;
cin>>width;
cout<<"Enter height"<<endl;
cin>>height;
volume=length*width*height;
cout<<"volume is = "<<volume;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ float length,width,height,volume;
cout<<"Enter length"<<endl;
cin>>length;
cout<<"Enter width"<<endl;
cin>>width;
cout<<"Enter height"<<endl;
cin>>height;
volume=length*width*height;
cout<<"volume is = "<<volume;
getch();
}
Write a program that find out the area of triangle when three sides a,b,c of triangle are given use appropriat statement to input the value of a,b,c from the keyboard . formula for the area of triangle is area= sqrt[s(s-a)(s-b)(s-c)]
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
float a,b,c,S,Area;
cout<<"enter the value of first side:"<<endl;
cin>>a;
cout<<"enter the value of second side:"<<endl;
cin>>b;
cout<<"enter the value of third side:"<<endl;
cin>>c;
S=(a+b+c)/2;
Area=sqrt(S*(S-a)*(S-b)*(S-c));
cout<<"The required area = "<<Area;
getch();
}
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
float a,b,c,S,Area;
cout<<"enter the value of first side:"<<endl;
cin>>a;
cout<<"enter the value of second side:"<<endl;
cin>>b;
cout<<"enter the value of third side:"<<endl;
cin>>c;
S=(a+b+c)/2;
Area=sqrt(S*(S-a)*(S-b)*(S-c));
cout<<"The required area = "<<Area;
getch();
}
Write a program that inputs basic salary and calculate 35% dearness allowness,25% house rent and then display gross salary in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ float bSalary;
cout<<"Input Basic salary to know Gross salary with 35% allownace & 25% House rent"<<endl;
//prompt to get salary from user;
cin>>bSalary;
//input into the bSalary;
cout<<"35% allownace is "<<bSalary*.35<<endl;
//35% of your basic salary is bSalary*.35
cout<<"25% House Rent is "<<bSalary*.25<<endl;
//same idea
cout<<"Gross Salary = "<<bSalary*(1-(.35+.25));
/*Gross or take-home salary is your base salary multiplied by one minus of .35 and .25, or .4*/
getch();
}
#include<conio.h>
using namespace std;
int main()
{ float bSalary;
cout<<"Input Basic salary to know Gross salary with 35% allownace & 25% House rent"<<endl;
//prompt to get salary from user;
cin>>bSalary;
//input into the bSalary;
cout<<"35% allownace is "<<bSalary*.35<<endl;
//35% of your basic salary is bSalary*.35
cout<<"25% House Rent is "<<bSalary*.25<<endl;
//same idea
cout<<"Gross Salary = "<<bSalary*(1-(.35+.25));
/*Gross or take-home salary is your base salary multiplied by one minus of .35 and .25, or .4*/
getch();
}
write a program that input a number and display its table
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int n,c;
c=1;
cout<<"Enter a number to get table"<<endl;
cin>>n;
while(c<=10)
{cout<<n<<"*"<<c<<" = "<<n*c<<endl;
c++;
} getch();
}
#include<conio.h>
using namespace std;
int main()
{ int n,c;
c=1;
cout<<"Enter a number to get table"<<endl;
cin>>n;
while(c<=10)
{cout<<n<<"*"<<c<<" = "<<n*c<<endl;
c++;
} getch();
}
WRITE a program that show all the possible combination of 123 with nested loop in c++
#include<iostream>
#include<conio.h>
using namespace std;
main ()
{ int i=1,j=1,k=1,l=1;
for(i=1;i<=3;i++)
{for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
cout<<"\t"<<i<<j<<k; }
}
getch();}
#include<conio.h>
using namespace std;
main ()
{ int i=1,j=1,k=1,l=1;
for(i=1;i<=3;i++)
{for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
cout<<"\t"<<i<<j<<k; }
}
getch();}
write a program that show A-Z alphabets with loop structure in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ char a;
a='A';
do{ cout<<a<<" "; a++;
} while(a<='Z');
getch();
}
#include<conio.h>
using namespace std;
int main()
{ char a;
a='A';
do{ cout<<a<<" "; a++;
} while(a<='Z');
getch();
}
Write a progtam that inputs marks from 0-100 and tells the grade of student with if statement in c++
#include<iostream>
using namespace std;
main()
{ int marks;
cout<<"Enter Marks to know grades"<<endl;
cin>>marks;
if(marks>=80)
cout<<"You have passed with A grade"<<endl;
else if(marks>=70)
cout<<"You have passed with B grade"<<endl;
else if(marks>=60)
cout<<"You have passed with C grade"<<endl;
else if(marks>=50)
cout<<"You have passed with D grade"<<endl;
else if(marks>=40)
cout<<"You have passed with E grade"<<endl;
else
cout<<"You have failed"<<endl;
system("pause");
}
using namespace std;
main()
{ int marks;
cout<<"Enter Marks to know grades"<<endl;
cin>>marks;
if(marks>=80)
cout<<"You have passed with A grade"<<endl;
else if(marks>=70)
cout<<"You have passed with B grade"<<endl;
else if(marks>=60)
cout<<"You have passed with C grade"<<endl;
else if(marks>=50)
cout<<"You have passed with D grade"<<endl;
else if(marks>=40)
cout<<"You have passed with E grade"<<endl;
else
cout<<"You have failed"<<endl;
system("pause");
}
Write a programe that input name from user with spaces and display on screen.
#include<iostream>
#include<conio.h>
using
namespace std;
int main()
{string n;
cout<<"enter
your name";
getline(cin,n);
cout<<"your
name is"<<n;
getch();
}
Friday, 11 December 2015
Write a program which display Pakistan 5 times with loop structure
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int a;
a=1;
do
{ cout<<a<<"=Pakistan"<<endl;
a++;
}while(a<=5); getch();
}
write a program that inputs 10 numbers as elements of array and tells the maximum and minimum number ....c++
#include<iostream>
using namespace std;
main()
{ int array[10],max,min;
cout<<"Enter Array Elements";
for(int a=0;a<10;a++)
cin>>array[a];
max=min=array[0];
for(int a=0;a<10;a++)
{
if(array[a]>max)
{ max=array[a];
}
if(array[a]<min)
min=array[a];
}
cout<<"the greater number is:"<<max<<endl;
cout<<"the minimum number is:"<<min;
}
using namespace std;
main()
{ int array[10],max,min;
cout<<"Enter Array Elements";
for(int a=0;a<10;a++)
cin>>array[a];
max=min=array[0];
for(int a=0;a<10;a++)
{
if(array[a]>max)
{ max=array[a];
}
if(array[a]<min)
min=array[a];
}
cout<<"the greater number is:"<<max<<endl;
cout<<"the minimum number is:"<<min;
}
Write a program that input temprature is fahrenheit and conver it into Celsius
#include<iostream>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{ float f,c;
cout<<"Enter temprature is fahrenheit to conver into Celsius"<<endl;
cin>>f;
c=5.0/9.0*(f-32.0);
cout<<"temprature in Celsius = "<<c;
getch();
}
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{ float f,c;
cout<<"Enter temprature is fahrenheit to conver into Celsius"<<endl;
cin>>f;
c=5.0/9.0*(f-32.0);
cout<<"temprature in Celsius = "<<c;
getch();
}
write a program that input 4 numbers and tells maximum number using if statement in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int a,b,c,d;
cout<<"Enter 4 numbers to find maximum number"<<endl;
cin>>a>>b>>c>>d;
if(a>b)
{ if(a>c)
{cout<<a<<" is maximum"<<endl;}
else if(a>d)
{cout<<a<<" is maximum"<<endl;}
else
{cout<<d<<" is maximum"<<endl;}
}
else if(b>c)
{ if(b>d)
{cout<<b<<" is maximum"<<endl;}
else
{cout<<d<<" is maximum"<<endl;}
}
else if(c>d)
cout<<c<<" is maximum"<<endl;
else
cout<<d<<" is maximum"<<endl;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ int a,b,c,d;
cout<<"Enter 4 numbers to find maximum number"<<endl;
cin>>a>>b>>c>>d;
if(a>b)
{ if(a>c)
{cout<<a<<" is maximum"<<endl;}
else if(a>d)
{cout<<a<<" is maximum"<<endl;}
else
{cout<<d<<" is maximum"<<endl;}
}
else if(b>c)
{ if(b>d)
{cout<<b<<" is maximum"<<endl;}
else
{cout<<d<<" is maximum"<<endl;}
}
else if(c>d)
cout<<c<<" is maximum"<<endl;
else
cout<<d<<" is maximum"<<endl;
getch();
}
write a program that inputs a number and tells whether it is prime or composit number using loop in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int c,num,p;
p=1;
cout<<"Enter an integer"<<endl;
cin>>num;
for(c=2;c<=num/2;c++)
if(num%c==0)
{
p=0;
break;}
if(p==1)
cout<<num<<" is a prime number";
else
cout<<num<<" is a composite number";
getch()
}
#include<conio.h>
using namespace std;
int main()
{ int c,num,p;
p=1;
cout<<"Enter an integer"<<endl;
cin>>num;
for(c=2;c<=num/2;c++)
if(num%c==0)
{
p=0;
break;}
if(p==1)
cout<<num<<" is a prime number";
else
cout<<num<<" is a composite number";
getch()
}
write a program that give the following shape using loop in c++
write a program which multiply numbers from 1 - 10 using loop in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int n,sum;
sum=1;
n=1;
while(n<=10)
{ sum=sum*n;
n++;
} cout<<"product is = "<<sum;
getch();}
#include<conio.h>
using namespace std;
int main()
{int n,sum;
sum=1;
n=1;
while(n<=10)
{ sum=sum*n;
n++;
} cout<<"product is = "<<sum;
getch();}
enter a number and reverse its digits using loop c++
program to Make diamond using loop in c++
#include<iostream>
#include <conio.h>
using namespace std;
int main()
{
int n=4,c,k,space=1;
space=n-1;
for(k=1;k<=n;k++)
{
for(c=1;c<=space;c++)
cout<<" ";
space--;
for(c=1;c<=2*k-1;c++)
cout<<"*";
cout<<endl;
}
space=1;
for(k=1;k<=n-1;k++)
{
for(c=1;c<=space;c++)
cout<<" ";
space++;
for(c=1;c<=2*(n-k)-1;c++)
cout<<"*";
cout<<endl;
}
getch();
}
#include <conio.h>
using namespace std;
int main()
{
int n=4,c,k,space=1;
space=n-1;
for(k=1;k<=n;k++)
{
for(c=1;c<=space;c++)
cout<<" ";
space--;
for(c=1;c<=2*k-1;c++)
cout<<"*";
cout<<endl;
}
space=1;
for(k=1;k<=n-1;k++)
{
for(c=1;c<=space;c++)
cout<<" ";
space++;
for(c=1;c<=2*(n-k)-1;c++)
cout<<"*";
cout<<endl;
}
getch();
}
Make A half diamond shap using loop in c++
#include<iostream>
#include <conio.h>
using namespace std;
int main()
{
int n=5,c,k,space=1;
space=n-1;
for(k=1;k<=n;k++)
{
for(c=1;c<=space;c++)
cout<<" ";
space--;
for(c=1;c<=2*k-1;c++)
cout<<"*";
cout<<endl;
} getch();
}
#include <conio.h>
using namespace std;
int main()
{
int n=5,c,k,space=1;
space=n-1;
for(k=1;k<=n;k++)
{
for(c=1;c<=space;c++)
cout<<" ";
space--;
for(c=1;c<=2*k-1;c++)
cout<<"*";
cout<<endl;
} getch();
}
Make A heart using loops in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
cout<<"\n\n\n\n\n\n\n";
for(int i=0;i<15;i++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int j=0;j<13;j++)
cout<<" ";
cout<<"* * * *";
cout<<endl;
for(int k=0;k<11;k++)
cout<<" ";
cout<<"* * * *";
cout<<endl;
for(int l=0;l<11;l++)
cout<<" ";
cout<<"* * * *";
cout<<endl;
for(int m=0;m<11;m++)
cout<<" ";
cout<<"* * *";
cout<<endl;
for(int n=0;n<11;n++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int o=0;o<12;o++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int p=0;p<13;p++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int q=0;q<14;q++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int r=0;r<15;r++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int s=0;s<17;s++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int t=0;t<20;t++)
cout<<" ";
cout<<"**";
cout<<endl;
getch();}
#include<conio.h>
using namespace std;
int main()
{
cout<<"\n\n\n\n\n\n\n";
for(int i=0;i<15;i++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int j=0;j<13;j++)
cout<<" ";
cout<<"* * * *";
cout<<endl;
for(int k=0;k<11;k++)
cout<<" ";
cout<<"* * * *";
cout<<endl;
for(int l=0;l<11;l++)
cout<<" ";
cout<<"* * * *";
cout<<endl;
for(int m=0;m<11;m++)
cout<<" ";
cout<<"* * *";
cout<<endl;
for(int n=0;n<11;n++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int o=0;o<12;o++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int p=0;p<13;p++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int q=0;q<14;q++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int r=0;r<15;r++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int s=0;s<17;s++)
cout<<" ";
cout<<"* *";
cout<<endl;
for(int t=0;t<20;t++)
cout<<" ";
cout<<"**";
cout<<endl;
getch();}
wite a program that inputs total numbers of students in class and input name of students and marks of student....and output highest marks and minimum marks with array
#include<iostream>
using namespace std;
main()
{ int max,min;
int marks[5];
string name[5];
for(int a=0;a<5;a++)
{
cout<<"enter name of roll number "<<a+1<<endl;
cin>>name[a];
cout<<"Enter marks of student"<<endl;
cin>>marks[a];}
min=max=marks[0];
for(int a=0;a<5;a++)
{
if(max<marks[a])
max=marks[a];
if(min>marks[a])
min=marks[a];}
cout<<"maximum marks are "<<max<<endl;
cout<<"minimum marks are "<<min;
}
using namespace std;
main()
{ int max,min;
int marks[5];
string name[5];
for(int a=0;a<5;a++)
{
cout<<"enter name of roll number "<<a+1<<endl;
cin>>name[a];
cout<<"Enter marks of student"<<endl;
cin>>marks[a];}
min=max=marks[0];
for(int a=0;a<5;a++)
{
if(max<marks[a])
max=marks[a];
if(min>marks[a])
min=marks[a];}
cout<<"maximum marks are "<<max<<endl;
cout<<"minimum marks are "<<min;
}
write a program which give following menu MANU OF PROGRAMpress 1: Add 2 two numbers"press 2: Add and multiply 3 numbers press 3: Enter two numbers and find maximum"press 4: Enter two numbers and find minimpress 5: Enter a value and find even or oddpress 6: Enter two values and swap them
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int number,a,b,c,sum,sum2,mul,swap;
cout<<" MANU OF PROGRAM"<<endl<<endl;
cout<<"press 1: Add 2 two numbers"<<endl<<endl;
cout<<"press 2: Add and multiply 3 numbers "<<endl<<endl;
cout<<"press 3: Enter two numbers and find maximum"<<endl<<endl;
cout<<"press 4: Enter two numbers and find minimum"<<endl<<endl;
cout<<"press 5: Enter a value and find even or odd"<<endl<<endl;
cout<<"press 6: Enter two values and swap them"<<endl<<endl;
cout<<"press a number 1-6"<<endl;
cin>>number;
if(number==1)
{ cout<<"Enter two numbers to add"<<endl;
cin>>a>>b;
sum=a+b;
cout<<"sum is = "<<sum<<endl;
}
else if(number==2)
{cout<<"Enter three numbers to add and multiply"<<endl;
cin>>a>>b>>c;
sum2=a+b+c;
mul=a*b*c;
cout<<"Sum is = "<<sum2<<endl;
cout<<"product is = "<<mul<<endl;
}
else if(number==3)
{cout<<"Enter two numbers to find maximum number"<<endl;
cin>>a>>b;
if (a>b)
cout<<a<<" is maximum"<<endl;
else if(b>a)
cout<<b<<" is maximum"<<endl;
}
else if(number==4)
{ cout<<"Enter two values to find minimum number "<<endl;
cin>>a>>b;
if(a<b)
cout<<a<<" is minimum"<<endl;
else if(b<a)
cout<<b<<" is minmum"<<endl;
}
else if(number==5)
{cout<<"Enter a number to find whether it is even or odd"<<endl;
cin>>a;
if(a%2==0)
cout<<a<<" is even"<<endl;
else
{
cout<<a<<" is odd"<<endl;}
}
else if(number==6)
{cout<<"Enter two values to swap"<<endl;
cin>>a>>b;
cout<<"you enter ("<<a<<","<<b<<")"<<endl;
swap=a;
a=b;
b=swap;
cout<<"values are swap = ("<<a<<","<<b<<")"<<endl;
}
else
cout<<"Enter values 1-6"<<endl;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ int number,a,b,c,sum,sum2,mul,swap;
cout<<" MANU OF PROGRAM"<<endl<<endl;
cout<<"press 1: Add 2 two numbers"<<endl<<endl;
cout<<"press 2: Add and multiply 3 numbers "<<endl<<endl;
cout<<"press 3: Enter two numbers and find maximum"<<endl<<endl;
cout<<"press 4: Enter two numbers and find minimum"<<endl<<endl;
cout<<"press 5: Enter a value and find even or odd"<<endl<<endl;
cout<<"press 6: Enter two values and swap them"<<endl<<endl;
cout<<"press a number 1-6"<<endl;
cin>>number;
if(number==1)
{ cout<<"Enter two numbers to add"<<endl;
cin>>a>>b;
sum=a+b;
cout<<"sum is = "<<sum<<endl;
}
else if(number==2)
{cout<<"Enter three numbers to add and multiply"<<endl;
cin>>a>>b>>c;
sum2=a+b+c;
mul=a*b*c;
cout<<"Sum is = "<<sum2<<endl;
cout<<"product is = "<<mul<<endl;
}
else if(number==3)
{cout<<"Enter two numbers to find maximum number"<<endl;
cin>>a>>b;
if (a>b)
cout<<a<<" is maximum"<<endl;
else if(b>a)
cout<<b<<" is maximum"<<endl;
}
else if(number==4)
{ cout<<"Enter two values to find minimum number "<<endl;
cin>>a>>b;
if(a<b)
cout<<a<<" is minimum"<<endl;
else if(b<a)
cout<<b<<" is minmum"<<endl;
}
else if(number==5)
{cout<<"Enter a number to find whether it is even or odd"<<endl;
cin>>a;
if(a%2==0)
cout<<a<<" is even"<<endl;
else
{
cout<<a<<" is odd"<<endl;}
}
else if(number==6)
{cout<<"Enter two values to swap"<<endl;
cin>>a>>b;
cout<<"you enter ("<<a<<","<<b<<")"<<endl;
swap=a;
a=b;
b=swap;
cout<<"values are swap = ("<<a<<","<<b<<")"<<endl;
}
else
cout<<"Enter values 1-6"<<endl;
getch();
}
Write a program that inputs total number of students and fee per student ang calculate total fee
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ float a,b,c;
cout<<"total number of student"<<endl;
cin>>a;
cout<<"Fee Per Student"<<endl;
cin>>b;
c=a*b;
cout<<"Total Fee ="<<c;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ float a,b,c;
cout<<"total number of student"<<endl;
cin>>a;
cout<<"Fee Per Student"<<endl;
cin>>b;
c=a*b;
cout<<"Total Fee ="<<c;
getch();
}
Write a program that input two numbers to swap them
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int a,b,temp;
cout<<"Enter two numbers to swap them"<<endl<<endl;
cout<<"Enter first number"<<endl;
cout<<"a = ";cin>>a;
cout<<"Enter the 2nd number"<<endl;
cout<<"b = ";cin>>b;
cout<<"Input numbers as ("<<a<<","<<b<<")"<<endl;
temp=a;
a=b;
b=temp;
cout<<"after swapping ("<<a<<","<<b<<")"<<endl;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ int a,b,temp;
cout<<"Enter two numbers to swap them"<<endl<<endl;
cout<<"Enter first number"<<endl;
cout<<"a = ";cin>>a;
cout<<"Enter the 2nd number"<<endl;
cout<<"b = ";cin>>b;
cout<<"Input numbers as ("<<a<<","<<b<<")"<<endl;
temp=a;
a=b;
b=temp;
cout<<"after swapping ("<<a<<","<<b<<")"<<endl;
getch();
}
write a program that input value in miles and it convert into km
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ float miles,km;
cout<<"enter the value in miles to convert in km:"<<endl;
cin>>miles;
km=miles*1.609;
cout<<miles<<" miles = "<<km<<" kilometer";
getch();
}
#include<conio.h>
using namespace std;
int main()
{ float miles,km;
cout<<"enter the value in miles to convert in km:"<<endl;
cin>>miles;
km=miles*1.609;
cout<<miles<<" miles = "<<km<<" kilometer";
getch();
}
write a program which inputs 4 numbers and add,multiply ang avg them.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int a,b,c,d,sum,mul;
float avg;
cout<<"Enter 4 numbers to get there sum,product & avg"<<endl;
cin>>a>>b>>c>>d;
sum=a+b+c+d;
mul=a*b*c*d;
avg=sum/4;
cout<<"sum is = "<<sum<<endl;
cout<<"product is ="<<mul<<endl;
cout<<"avg is = "<<avg;
getch();
}
#include<conio.h>
using namespace std;
int main()
{ int a,b,c,d,sum,mul;
float avg;
cout<<"Enter 4 numbers to get there sum,product & avg"<<endl;
cin>>a>>b>>c>>d;
sum=a+b+c+d;
mul=a*b*c*d;
avg=sum/4;
cout<<"sum is = "<<sum<<endl;
cout<<"product is ="<<mul<<endl;
cout<<"avg is = "<<avg;
getch();
}
Wednesday, 9 December 2015
Enter 5 digit number to reverse it in c++
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{int digit,a,b,c,d;
cout<<"enter 5 digit number to reverse it"<<endl;
cin>>digit;
a=digit/10000;
digit=digit%10000;
b=digit/1000;
digit=digit%1000;
c=digit/100;
digit=digit%100;
d=digit/10;
digit=digit%10;
cout<<digit<<d<<c<<b<<a;
getch();
}
#include<conio.h>
using namespace std;
int main()
{int digit,a,b,c,d;
cout<<"enter 5 digit number to reverse it"<<endl;
cin>>digit;
a=digit/10000;
digit=digit%10000;
b=digit/1000;
digit=digit%1000;
c=digit/100;
digit=digit%100;
d=digit/10;
digit=digit%10;
cout<<digit<<d<<c<<b<<a;
getch();
}
Subscribe to:
Posts (Atom)