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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Sign up to vote on this title
UsefulNot useful