Professional Documents
Culture Documents
Programs 140903050145 Phpapp02
Programs 140903050145 Phpapp02
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a,b,sum,sub,mul,div;
cin>>a>>b;
sum=a+b;
sub=a-b;
mul=a*b;
div=a/b;
cout<<"\nSum:"<<sum;
cout<<"\nSubtraction:"<<sub;
cout<<"\nMultipication:"<<mul;
cout<<"\nDivision:"<<div;
getch();
1
Output :
2
// 2. Program to calculate simple interest
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int principle,rate,time,si;
cin>>principle;
cin>>rate;
cout<<interest;
si=(principle*rate*time)/100;
getch();
3
Output :
4
// 3. Program to implement increment and decrement operators
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int x=5,y=5;
cout<<x++;
cout<<"\n";
cout<<++x;
cout<<"\n";
cout<<y++;
cout<<"\n";
cout<<++y;
getch();
5
Output :
6
// 4. Program to implement if-else statements
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int year;
cin>>year;
if(year%4==0)
else
getch();
7
Output :
8
// 5. Program to implement if-else if ladder statement
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
float sal;
float tax;
cin>>sal;
if(sal>=9000)
tax=sal*0.4;
else if((sal>=7500)&&(sal<8999))
tax=sal*0.3;
else
tax=sal*0.2;
cout<<"Tax:"<<tax;
getch();
9
Output :
10
// 6. Program to implement switch case statement
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int ch;
cin>>ch;
switch(ch)
break;
break;
break;
break;
getch();
11
Output :
12
// 7. Program to implement while loop and it computes a power of b
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
float a;
int b;
float pow;
cin>>a>>b;
pow=1.0;
while(b>=1)
pow=pow*a;
b--;
cout<<"Power : "<<pow;
getch();
13
Output :
14
// 8. Program to implement do while and it computes the factorial of a number
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int num,fact=1;
cin>>num;
do
fact=fact*num;
num--;
while(num!=0);
cout<<"\nFactorial :"<<fact;
getch();
15
Output :
16
// 9. Program to display an array
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[5],i;
for(i=0;i<5;i++)
cin>>a[i];
for(i=0;i<5;i++)
cout<<"\n"<<a[i];
getch();
17
Output :
18
// 10. Program to display multiples of a number using for loop
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int i,num;
cin>>num;
for(i=1;i<=10;i++)
cout<<"\n"<<num*i;
getch();
19
Output :
20