You are on page 1of 11

Program 1: calculate simple interest using if statement where

the conditions are


 If time<2 then rate of interest is 7%
 if time is between 2 to 5 years then rate
of interest is 6.5%
 otherwise rate of interest is 6%
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

float p,r,si,t;

cout<<"enter the values of\n principle\n time";

cin>>p>>t;

if(t<2)

cout<<"rate of interest is 7%\n";

r=0.07;

else if ((t>=2)&&(t<5))

cout<<"rate of interest is 6.5%\n";

r=0.065;

else

cout<<"rate of interest is 6%\n";


r=0.06;

si=p*r*t;

cout<<"the simple interest is "<<si;

getch();

}
Program 2: find mean ,variance and standard
deviation using switch case like
 Using for loop
 Using while loop
 Using do while loop
#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

clrscr();

int ch,j,k=0,n[10],sum=0,sum1=0;

float sd,v,m;

cout<<"enter any 10 numbers";

for(int i=0;i<10;i++)

cin>>n[i];

cout<<"enter any choice out of 1,2,3\n";

cout<<"1. using for loop\n";

cout<<"2. using while loop\n";

cout<<"3. using do while loop";

cin>>ch;

switch(ch)

case 1:

for(int i=0;i<10;i++)
{

sum=sum+n[i];

sum1=sum1+(n[i]*n[i]);

m=sum/10.0;

v=(sum1/10.0)-(m*m);

sd=pow(v,0.5);

cout<<"mean is "<<m<<"\n"<<"variance is"<<v<<"\n"<<"standard deviation is"<<sd;

break;

case 2:

while(j<10)

sum=sum+n[j];

sum1=sum1+(n[j]*n[j]);

j++;

m=sum/10.0;

v=(sum1/10.0)-(m*m);

sd=pow(v,0.5);

cout<<"mean is "<<m<<"\n"<<"variance is"<<v<<"\n"<<"standard deviation is"<<sd;

break;

case 3:

do{

sum=sum+n[k];

sum1=sum1+(n[k]*n[k]);

k=k+1;

}
while(k<10);

m=sum/10.0;

v=(sum1/10.0)-(m*m);

sd=pow(v,0.5);

cout<<"mean is "<<m<<"\n"<<"variance is"<<v<<"\n"<<"standard deviation is"<<sd;

break;

default:cout<<"invalid choice";

getch();

}
Program 3: using structures enter employee
details and calculate tax according to their age
and salary
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

struct emp

char n[50];

char g[10];

char d[20];

long s;

int a;

}emp;

float tax;

cout<<"enter details of the employee\n";

cout<<"the name of the employee is \n";

cin>>emp.n;

cout<<"gender of the employee is \n";

cin>>emp.g;

cout<<"designation of the employee is \n";

cin>>emp.d;

cout<<"salary of the employee is \n";

cin>>emp.s;
cout<<"age of the employee is \n";

cin>>emp.a;

if(emp.a<60)

if(emp.s<250000)

cout<<"tax is nil\n";

tax=0;

else if ((emp.s>250000)&&(emp.s<500000))

cout<<"tax is 5%\n ";

tax=0.50*emp.s;

else if ((emp.s>500000)&&(emp.s<1000000))

cout<<"tax is 20% \n";

tax=0.20*emp.s;

else

cout<<"tax is 30%\n";

tax=0.30*emp.s;

else

{
if(emp.s<500000)

cout<<"tax is nil \n";

tax=0;

else if((emp.s>500000)&&(emp.s<1000000))

cout<<"tax is 20% \n";

tax=0.20*emp.s;

else

cout<<"tax is 30% \n";

tax=0.30*emp.s;

cout<<"tax payable according to employee's salary is "<<tax;

getch();

You might also like