By: Ayushi Agrawal: Class: Xi Science
By: Ayushi Agrawal: Class: Xi Science
FILE
BY : AYUSHI AGRAWAL
CLASS : XI SCIENCE
SIMPLE PROGRAMS
Q1 :WAP TO FIND MAXIMUM NUMBER BETWEEN THREE NUMBERS
PROGRAM
# include<iostream.h>
#include<conio.h>
int main()
{
float a,b,c,max,great;
cout<<"\n enter first number :";
cin>>a;
max=(a>b)? a:b;
great=(c>max)? c:max;
cout<<"\n maximum number is: "<<great;
getch();
}
OUTPUT
Q2:WAP TO CONVERT TIME FROM HOURS TO SECONDS
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
int hrs,sec;
cout<<"Enter the time you study in hours ";
cin>>hrs;
sec=hrs*3600;
cout<<"Time in seconds is: "<<sec<<endl;
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float rs,p,d;
cout<<"Enter the amount in rupees ";
cin>>rs;
p=rs/102.89;
cout<<"Amount in pound is: "<<p<<endl;
d=rs/60.02;
cout<<"Amount in dollar is: "<<d<<endl;
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
char ch=' ';
int num=ch;
cout<<"ASCII code of backspace is: "<<num<<endl;
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
char ch;
cout<<"Enter the character ";
cin>>ch;
int num=ch;
cout<<"ASCII code is: "<<num<<endl;
getch();
}
OUTPUT
Q6 :WAP TO FIND THE ASCII CODE OF A DIGIT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
char ch;
cout<<"Enter the digit ";
cin>>ch;
int num=ch;
cout<<"ASCII code of the given digit is: "<<num<<endl;
getch();
}
OUTPUT
IF-ELSE PROGRAMS
Q7 :WAP TO FIND THE COMMISSION ON GIVEN SALES AMOUNT
PROGRAM
#include<iostream.h>
#include<conio.h>
int main()
{
float com;
int salesamt;
cin>>salesamt;
if(salesamt<=1000)
com=salesamt*3/100;
else if(salesamt>1000&&salesamt<=10000)
com=salesamt*9/100;
else
com=salesamt*12/100;
getch();
OUTPUT
Q8 :WAP TO FIND IF A STUDENT IS SELECTED FOR ADMISSION OR NOT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
char name[20];
float per_marks;
int category;
cout<<"Enter your name ";
gets(name);
cout<<"Enter your category - \n 1.SC \n 2.OBC \n 3.GENERAL\n ";
cin>>category;
cout<<"Enter your per_marks ";
cin>>per_marks;
if(category==1||category==2)
per_marks=per_marks+per_marks*5/100;
if(per_marks>=80)
cout<<"SELECTED FOR ADMISSION ";
else
cout<<"NOT SELECTED ";
getch();
}
OUTPUT
Q9 :WAP TO FIND THE FINE AMOUNT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
char name[20];
int n,fine;
cout<<"Enter your name ";
gets(name);
cout<<"Enter number of days book returned late ";
cin>>n;
if(n>0&&n<=5)
fine=40*n;
else
fine=200+60*n;
cout<<"Fine amount is "<<fine<<" paisa ";
getch();
}
OUTPUT
PROGRAMS BASED ON EXPRESSIONS
Q10 :WAP TO SOLVE THE GIVEN EXPRESSION
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float D;
int b,a,c;
cout<<"Enter the value of b ";
cin>>b;
cout<<"Enter the value of a ";
cin>>a;
cout<<"Enter the value of c ";
cin>>c;
D=pow(b,2)-4*a*c;
cout<<"value of p is: "<<D<<endl;
getch();
}
OUTPUT
Q11 :WAP TO SOLVE THE GIVEN EXPRESSION
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float P;
int r,s;
cout<<"Enter the value of r ";
cin>>r;
cout<<"Enter the value of s ";
cin>>s;
P=sqrt(pow((r+s),2));
cout<<"value of p is: "<<P<<endl;
getch();
}
OUTPUT
Q12 :WAP TO SOLVE THE GIVEN EXPRESSION
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float ROOT;
int b,a,c;
cout<<"Enter the value of b ";
cin>>b;
cout<<"Enter the value of a ";
cin>>a;
cout<<"Enter the value of c ";
cin>>c;
ROOT=(sqrt(-b+pow(b,2)))/(2*a)-4*a*c;
cout<<"value of p is: "<<ROOT<<endl;
getch();
}
OUTPUT
SWITCH CASE PROGRAMS
Q13 :WAP TO GIVE OUTPUT BASED ON USERS CHOICE
PROGRAM
#include<iostream.h>
#include<conio.h>
int main()
{
int choice;
cout<<"Enter your choice - \n"
<<"1.Cricketer of the Millennium \n"
<<"2.Footballer of the Millennium \n"
<<"3.Basketballer of the Millennium \n";
cin>>choice;
switch(choice)
{
case 1: cout<<"Sachin Tendulkar\n";
break;
case 2: cout<<"pele\n";
break;
case 3: cout<<"Magic Johnson";
break;
default:cout<<"Idiot of the Millennium\n"
<<"You.......cos your choicewas only 1 , 2 or 3";
break;
}
getch();
}
OUTPUT
Q14 :WAP TO CALCULATE SALARY
PROGRAM
#include<iostream.h>
#include<conio.h>
int main()
{
char grade;
float DA,HA,ITAX,salary;
int Basic_Pay;
cout<<"Enter your grade (a/b/c) ";
cin>>grade;
switch(grade)
{
case 'a': Basic_Pay=50000;
DA=Basic_Pay*40/100;
HA=Basic_Pay*50/100;
ITAX=Basic_Pay*30/100;
break;
case 'b': Basic_Pay=20000;
DA=Basic_Pay*30/100;
HA=Basic_Pay*40/100;
ITAX=Basic_Pay*15/100;
break;
case 'c': Basic_Pay=12000;
DA=Basic_Pay*20/100;
HA=Basic_Pay*30/100;
ITAX=Basic_Pay*6/100;
break;
default:cout<<"Wrong Choice";
break;
}
salary=Basic_Pay+DA+HA-ITAX;
cout<<"Salary is "<<salary;
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
int main()
{
int age,charges;
cout<<"Enter your age ";
cin>>age;
switch(age)
{
case 1: case 2: case 3:
charges=0;
break;
case 4: case 5: case 6:
charges=50;
break;
case 7: case 8: case 9: case 10:
charges=80;
break;
default:
charges=100;
break;
}
cout<<"\t FANTASY LAND \n"
<<" Customer'a Age : "<<age<<" years"<<endl
<<" Ticket charges : Rs."<<charges<<endl;
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,flag=0;
cout<<"Enter number ";
cin>>n;
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
cout<<"number is not prime ";
flag=1;
break;
}
}
if(flag==0)
cout<<"number is prime ";
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
for(int i=5;i>=1;i--)
{
for(int j=i;j<=5;j++)
{
cout<<j<<" ";
}
cout<<endl;
}
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
for(int i=5;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
cout<<i<<" ";
}
cout<<endl;
}
getch();
}
OUTPUT
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,t;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1,t=n-1;i<=n*2-1;i+=2,t--)
{
for(int k=t;k>=1;k--)
cout<<" ";
for(int j=1;j<=i;j++)
{
cout<<'*';
}
cout<<endl;
}
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,sumo=0,sume=0,i;
cout<<"Enter number of terms ";
cin>>n;
i=1;
while(i<=n)
{
if(i%2==0)
sume+=i;
else
sumo+=i;
i++;
}
cout<<"Sum of even numbers is "<<sume<<endl;
cout<<"Sum of odd numbers is "<<sumo<<endl;
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i,sum=0,n,r;
cout<<"Enter a number ";
cin>>n;
i=0;
while(n)
{
r=n%10;
sum+=r;
n=n/10;
}
cout<<"Sum of given digits is "<<sum;
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i,n,r,num=0;
cout<<"Enter a number ";
cin>>n;
i=0;
while(n)
{
r=n%10;
num=num*10+r;
n=n/10;
}
cout<<"Reverse of the given number is "<<num;
getch();
}
OUTPUT
DO WHILE PROGRAMS
Q23 :WAP TO FIND THE FACTORIAL A NUMBER
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,p=1;
cout<<"Enter a number ";
cin>>n;
do
{
p*=n;
n--;
}while(n);
cout<<"Factorial of a given number is "<<p;
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,r,sum=0,temp;
cout<<"Enter a number ";
cin>>n;
temp=n;
do
{
r=n%10;
sum+=(r*r*r);
n=n/10;
}while(n);
if(sum==temp)
cout<<"Number is armstrong ";
else
cout<<"Number is not armstrong ";
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,num,i=1,s,hcf;
cout<<"Enter any two numbers ";
cin>>n>>num;
if(n>num)
s=num;
else
s=n;
do
{
if(num%i==0 && n%i==0)
{
hcf=i;
}
i++;
}while(i<=s);
cout<<"HCF of given numbers is "<<hcf;
getch();
}
OUTPUT
1D ARRAY PROGRAMS
Q26 :WAP TO FIND THE PRODUCT OF ELEMENTS IN THE ARRAY
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int prod=1;
const int size=8;
int a[size];
for(int i=0;i<size;i++)
{
cout<<"Enter number "<<i+1<<": ";
cin>>a[i];
prod*=a[i];
}
cout<<"product of elements is "<<prod<<endl;
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int temp;
const int size=8;
int a[size];
for(int i=0;i<size;i++)
{
cout<<"Enter number "<<i+1<<": ";
cin>>a[i];
}
temp=a[0];
a[0]=a[size-1];
a[size-1]=temp;
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
getch();
}
OUTPUT
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int sum=0;
float avg;
const int size=8;
int a[size];
for(int i=0;i<size;i++)
{
cout<<"Enter number "<<i+1<<": ";
cin>>a[i];
sum+=a[i];
}
cout<<"sum of elements is "<<sum<<endl;
avg=(float)sum/size;
cout<<"average of elements is "<<avg;
getch();
}
OUTPUT
2D ARRAY PROGRAMS
Q29 :WAP TO CONVERT A 2D MATRIX INTO1D MATRIX
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int p=2,q=2,k=0;
int a[p][q],sum=0,b[k];
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
b[k++]=a[i][j];
}
}
for(int k=0;k<p*p;k++)
{
cout<<b[k]<<" ";
}
getch();
}
OUTPUT
Q30 :WAP TO PRINT UPPER TRIANGULAR ELEMENTS
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int p=2,q=2;
int a[p][q];
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
if(i<=j)
cout<<a[i][j]<<" ";
else
cout<<" ";
}
cout<<endl;
}
getch();
}
OUTPUT
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int p=2,q=2;
int a[p][q],usum=0,lsum=0;
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
for(int i=0;i<p;i++)
{
for(int j=0;j<q;j++)
{
if(i<=j)
usum+=a[i][j];
if(i>=j)
lsum+=a[i][j];
}
}
cout<<"sum of upper triangle elements is "<<usum<<endl;
cout<<"sum of lower triangle elements is "<<lsum;
getch();
}
OUTPUT
STRUCTURE PROGRAMS
Q32 :WAP TO FIND NYMBER OF STUDENTS IN EACH STREAM
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
struct student
{
int roll;
char name[20];
char stream;
};
student st[20];
int main()
{
int ncount=0,mcount=0,acount=0,ccount=0;
for(int i=0;i<20;i++)
{
cout<<"Enter your name ";
cin>>st[i].name;
cout<<"Enter your roll number ";
cin>>st[i].roll;
cout<<"Enter your stream (n/m/a/c) ";
cin>>st[i].stream;
if(st[i].stream=='n')
ncount+=1;
else if(st[i].stream=='m')
mcount+=1;
else if(st[i].stream=='a')
acount+=1;
else if(st[i].stream=='c')
ccount+=1;
}
cout<<"Number of students in medical science are "<<mcount<<endl;
cout<<"Number of students in non-medical are "<<ncount<<endl;
cout<<"Number of students in arts stream are "<<acount<<endl;
cout<<"Number of students in commerce stream are "<<ccount;
getch();
}
OUTPUT
Q33 :WAP TO FIND MORE EXPERIENCED CANDIDATE
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
struct details
{
char name[20];
int age;
int ex_year;
int ex_month;
char addr[80];
}d1,d2;
void select_candidate(details d1,details d2)
{
details t;
if(d1.ex_year>d2.ex_year)
t=d1;
else if(d1.ex_year==d2.ex_year && d1.ex_month>d2.ex_month)
t=d1;
else
t=d2;
cout<<t.name<<endl;
cout<<t.age<<endl;
cout<<t.addr<<endl;
cout<<t.ex_year<<endl;
cout<<t.ex_month<<endl;
}
int main()
{
details x={"Aman",40,45,38,"lockshed"};
details y={"Raman",38,45,36,"pari chock"};
select_candidate(x,y);
getch();
}
OUTPUT
Q34 :WAP TO FIND THE CANDIDATE ELIGIBLE FOR BONUS
PROGRAM
#include<iostream>
#include<conio.h>
using namespace std;
struct employee
{
char name[20];
int ID;
float sal;
}T;
int eligible_for_bonus(employee p);
int main()
{
int k;
cout<<"Enter employee ID ";
cin>>T.ID;
cout<<"Enter employee name ";
cin>>T.name;
cout<<"Enter basic salary ";
cin>>T.sal;
k=eligible_for_bonus(T);
if(k==1)
cout<<"Eligible for bonus ";
else
cout<<"Not eligible for bonus ";
getch();
}
int eligible_for_bonus(employee p)
{
if(p.sal<15000)
return 1;
else
return 0;
}
OUTPUT