C++ programme using if statement.

Write a prom to test whether the given nu. Is even or odd
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int var;
cout<<”enter any nu”;
cin>>var;
if(var%2==0)
{
cout<<”even”;
}
if(var%2!=0)
{
cout<<odd;
}
getch();
}

To compare two nu.and print the greater nu.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int nu1,nu2;
cout<<”enter any nu”;
cin>>nu1>>nu2;
if(nu1>nu2)
{
cout<<nu1<<”is greater than”<<nu2;
}
if(nu2>nu1)
{
cout<<nu2<<”is greater than”<<nu2;
}
getch();
}

To calculate income tax according to following table:

000) { cout<<”income tax is=”<<nil. if(sal<5.50. cin>>sal.000)&&(sal<=10.h> void main() { clrscr().h> #include<conio.000)) { cout<<tax is=<<(sal*5/100). cout<<”input your salary”.000 10% 50.000-10.000 5% 10. } 15% 20% .001-1.50. int sal. } If((sal>5.000 More than 1.000 Nil 5.001-50.Salary range Income Tax Less than Rs 5. 000 #include<iostream.

50. } . } if(sal>1. } getch().if((sal>10000)&&(sal<=50000)) { cout<<”tax is= ”(sal*10/100). } if((sal>50001)&&(sal<=150000)) { cout<<”tax is =”<<(sal*15/100).000) { cout<<”tax is =”<<(sal*20/100).

} getch(). cin>>age.C++ programme using if else statement. } else { cout<<you cannot vote. cout<<”enter your age”. #include<iostream. if(age>18) { cout<<”you can vote”. } . int age. WAP to input the age of the user and check wheather the user is valid to vote.h> void main() { clrscr().h> #include<conio.

if(a>b)&&(a>c) { cout<<”greatest number is”<<a. } else { cout<<”greatest number is”<<c.h> #include<conio. .h> void main() { clrscr(). #include<iostream. } else { if(b>c) { cout<<”greatest number is”<<b. cout<<”enter three number”. cin>>a>>b>>c.b.WAP to compare three numbers and display the greatest number.c. int a.

h> #include<conio. cin>>year. int year.h> void main() { clrscr(). cout<<”enter the year is”.} } getch(). } WAP to check wheather a year is leap year or not. if((year%4==0)&&(year%100!=0)) { cout<<”leap year”. } getch(). } . #include<iostream. } else { cout<<not a leap year.

} getch(). cout<<”enter three sides of triangle”. if((b+c)>a&&(a+c)>b) { cout<<”triangle will form”. } else { cout<<”no triangle will form”.h> #include<conio. cin>>a>>b>>c.c. int a.WAP to input three sides of triangle and ascertion wheather these three sides will form a triangle or not. } .b.h> void main() { clrscr(). #include<iostream.

float f.WAP to convert temperature to farenhite or celcious as per users choice. cout<<”temperature in farenhite=”<<f. } else { cout<<”input temperature in farenhite”. f=9/5*(c+32). cin>>f. if(ch==1) { cout<<”input temperature in celcious”.h> void main() { clrscr(). int ch. cin>>c. #include<iostream.h> #include<conio. .c. cout<<”input 1 to convert celcious to farenhite or 2 to convert farenhite to celcious”. cin>>ch.

} getch(). cout<<”temperature in celcious=”<<c. } .c=5/9*(f-32).

WAP to check wheather a number is divided by 13. if(n%13==0) { cout<<”number is divided by 13”. } getch().h> void main() { clrscr(). } .h> #include<conio. int n. #include<iostream. cout<<”input a number”. } else { cout<<”number is not divided by 13”. cin>>n.

int a. #include<iostream. } else { cout<<”it is not a triangle” .c.h> void main() { clrscr().b. } getch(). } . if((a*a==(b*b+c*c))||(b*b==(a*a+c*c))||(c*c==(a*a+b*b))) { cout<<”it is a right triangle”. cout<<”enter three sides of triangle”. cin>>a>>b>>c.WAP to input three sides of triangle and wheather it is a right triangle.h> #include<conio.

s. .h> #include<conio. } else { C=n*n*n. int n.WAP to input a number and display its square if it is less than 50 else display its cube. } getch(). cout<<”square number is =”<<s. cout<<”input a number”. if(n<50) { S=n*n. } C++ programme using switch statement. #include<iostream. cin>>n.c. cout<<”cube of number is=”<<c.h> void main() { clrscr().

#include<iostream. . cout<<”enter the number”.WAP to display a menu with options add. cin>>i. Case 2: cout<<”substract is=”<<p-q. cout<<”2. cout<<”choose an option from given number”.multiply”. break. Do the respective operations on selection. cout<<”1.h> #include<conio. switch(i) { Case 1: cout<<”sum is=”<<p+q.i.substract.add”. cout<<”3. int p.h> void main() { clrscr(). cout<<”4. cin>>p>>q.q.multiply and divide.substract”.divide”.

} . break. default: cout<<”invalid choice”.break. Case 3: cout<<”multiply is=”<<p*q. } getch(). break. Case 4: cout<<”divide is=”<<p/q. break.

WAP to read the marital status and display messages according to the following chart: Marital Status Message M Married S Single D Devorce W Widow #include<iostream.h> void main() { clrscr(). break. char MS.h> #include<conio. Case S: cout<<”Single”. Case D: . switch(i) { Case M: cout<<”Married”. break.

break.cout<<”Devorce”. } getch(). } . default: cout<<”\n invalid entry”. Case w: cout<<”\n widow”. break. b9reak.

h> void main() { clrscr().y.C++ programme using GOTO statement. } Count=count+1. float x. avg: cout<<”enter a number”.h> #include<conio. . cout<<end1. } else { Y=sqrt(x). int count=1. WAP to find square root for five numbers. cin>>x. cout<<”square root=”<<y. #include<iostream. if(x<0) { cout<<”invalid number”.

} . cout<<”finished”.If(count<=5) Goto avg. getch().

}//closing of main }closing of class Programme in java WAP to assign two numbers and calculate their sum. …………. a=20. class Number { public static void main(String arg[]) { int a. //body of the program ………….b.c. . ………….General programming format in java class class name { public static void main(String arg[]) { ………….

out. c=a+b. System.println(“the sum is=”). } } .println(area).out.area.b=30. System.println(“the are of rectangle is=”). b=30. area=l*b. l=20. System. class Rectangle { public static void main(String arg[]) { int l. System.out.b.out.println(c). } } WAP to assign the length and breadth of a rectangle and calculate its area.

Sign up to vote on this title
UsefulNot useful