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

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

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

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

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

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

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

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

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

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

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

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

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

char MS.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. break. break. Case D: . switch(i) { Case M: cout<<”Married”.h> void main() { clrscr().h> #include<conio. Case S: cout<<”Single”.

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

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

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

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

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