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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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