You are on page 1of 21

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:

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

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

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

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

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

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

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

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

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

c. int a. #include<iostream.h> #include<conio.b. cout<<”enter three sides of triangle”. cin>>a>>b>>c.h> void main() { clrscr(). } . } else { cout<<”it is not a triangle” .WAP to input three sides of triangle and wheather it is a right triangle. } 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<<”cube of number is=”<<c. if(n<50) { S=n*n.c.WAP to input a number and display its square if it is less than 50 else display its cube. #include<iostream. cout<<”input a number”.s. cout<<”square number is =”<<s.h> #include<conio. } else { C=n*n*n. int n.h> void main() { clrscr(). cin>>n. } getch(). } C++ programme using switch statement.

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

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

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

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

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

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