1.Write a program to enter a no. and check whether the no. is even or odd?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<" Laxman"<<endl;
cout<<"enter a"<<endl;
cin>>a;
if(a%2==0)
cout<<"even";
else
cout<<"odd";
getch();
}
2. Write a program that in a company 10% of salary is deducted for income tax and 8% forprovident fund if the salary is greater than 6000 but if the salary isless than or equal to 6000 then 8% is deducted for income tax and 5% isdeducted for provident fund. Write a program to accept the basic salaryfrom the user and calculate the net salary?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
float sal,tax=0;
cout<<"Enter salary"<<endl;
cin>>sal;
if(sal>6000)
{
tax=(sal*0.1)+(sal*0.08);
}
else
{
tax=(sal*0.08)+(sal*0.05);
}
cout<<sal-tax;
getch();
}
3.Write a program to accept marks in three subjects from the user, calculate the percentage and print the grade accordingly?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" Laxman"<<endl;
int cso,oops,ada,sum=0;
cout<<"enter the marks"<<endl;
cin>>cso>>oops>>ada;
sum=(cso+oops+ada)/3;
if(sum>90)
{
cout<<"Grade=A";
}
else if(sum>80)
{
cout<<"Grade=B";
}
else if(sum>70)
{
cout<<"Grade=C";
}
else
{
cout<<"Fail";
}
getch();
}
4.Write a program to accept three numbers and print the maximum value?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" Laxman"<<endl;
int a,b,c;
cout<<"enter the no's";
cin>>a>>b>>c;
if(a>b&&a>c)
cout<<"a is greater";
else if(b>c&&b>a)
cout<<"b is greater";
else
cout<<"c is greater";
getch();
}
5.Write a program to simulate the calculator to perform the following operation on two numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
char c;
cout<<" Laxman "<<endl;
cout<<"enter the no";
cin>>a>>b;
cout<<"enter the operation";
cin>>c;
switch(c)
{
case '+':
{
b=a+b;
break;
}
case '-':
{
b=a-b;
break;
}
case '*':
{
b=a*b;
break;
}
case '/':
{
b=a/b;
break;
}
default:
cout<<"wrong choice";
}
cout<<b;
getch();
}
6.Write a program to find the area of a circle, area of rectangle and area of triangle according to the user choice by switch statement.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,d;
char c;
cout<<" Laxman "<<endl;
cout<<"enter the operation"<<endl;
cout<<”c=circle,r=rectangle,t=triangle”;
cin>>c;
switch(c)
{
case 'c':
{
cout<<"enter the radius";
cin>>a;
d=(2*3.14)*a;
cout<<d;
break;
}
case 'r':
{
cout<<"enter the length and breadth"<<endl;
cin>>a>>b;
d=a*b;
cout<<d;
break;
}
case 't':
{
cout<<"enter the breadth & height";
cin>>a>>b;
d=(a+b)/2;
cout<<d;
break;
}
default:
cout<<"wrong choice";
}
getch();
}
7.Write a progarm to accept a series of positive numbers terminated by 0 and then print the smallest and the largest no in sequence.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n=1,max=0,min=0;
cout<<" Laxman "<<endl;
for( ;n!=0; )
{
cout<<"enter the no.";
cin>>n;
if(n>max)
{
max=n;
}else if(n<min)
{
min=n;
}
}
cout<<max<<endl<<min;
getch();
}
8.Write a program to accept two numbers from the user and check that the first no is divisible by the second number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a,b;
cout<<"enter no."<<endl;
cin>>a>>b;
if(a%b==0)
cout<<"No."<<a<<"is divisible by"<<b;
else
cout<<"No. is not divisible";
getch();
}
9.Write a program to check whether the year is leap year or not.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int y;
cout<<"Enter Year"<<endl;
cin>>y;
if(y%4==0)
cout<<"Leap Year";
else
cout<<"Not Leap Year";
getch();
}
10.Write a progarm to print the average of three no given by user till user wants.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a,b,c,avg;
char d;
do
{
cout<<"Enter the no's"<<endl;
cin>>a>>b>>c;
avg=(a+b+c)/3;
cout<<"average is"<<avg;
cout<<"\nwant to continue";
cin>>d;
}
while(d=='y'
d=='Y');
getch();
}
11.Write a program to generate all prime from 1 to 300.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int p,i,j;
cout<<"prime no. are as follows"<<endl;
for(i=1;i<=300;i++)
{
p=1;
for(j=2;j<=i;j++)
{
if(i==j)
continue;
else if(i%j==0)
p=0;
}
if(p)
cout<<i<<"\t";
}
getch();
}
12.Write a program to generate FLOYD’s triangle up to 5 rows.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a=1,i,j;
for(i=0;i<=5;i++)
{
for(j=0;j<i;j++)
{
cout<<a<<" ";
a=a+1;
}
cout<<"\n";
}
getch();
}
13.Write a program to enter base and index value and calculate the power of two no.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a,b,p=0;
cout<<"Enter the no."<<endl;
cin>>a>>b;
p=pow(a,b);
cout<<"Power ="<<p;
getch();
}
Without using math.h
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a,b,p,i;
cout<<"Enter the Base";
cin>>a;
cout<<"\nEnter the power";
cin>>b;
p=a;
for(i=1;i<b;i++)
{
p=p*a;
}
cout<<p;
getch();
}
14.Write a program to check whether the number is prime or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,p=1,j;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the no.";
cin>>a;
for(j=2;j<a;j++)
{
if(a%j==0)
{
p=2;
}
}
if(p==1)
cout<<"No. is Prime";
else
cout<<"No. is not Prime";
getch();
}
15.Write a program to check the type of character entered from the keyboard.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"\t\t\t\t\tLaxman"<<endl;
char c;
cout<<"Enter the character:\n";
cin>>c;
if(c>='a'&&c<='z')
cout<<"Lower Case Element";
else if(c>='A'&&c<='Z')
cout<<"Upper Case Element";
else if(c>='0'&&c<='9')
cout<<"Digit Character";
else
cout<<"Special Character";
getch();
}
By-Laxman
CSE
TITR Bhopal
No comments:
Post a Comment