Conditional Programs
Conditional Programs
QNO1: Write a program that asks the user to input 2 numbers now determine
which number is greater and print the result.
#include<iostream>
#include<math.h>
int main()
int n1,n2;
cin>>n1;
cin>>n2;
int Max=n1;
if(Max<n2)
Max=n2;
cout<<"Max is"<<Max<<endl;
return 0 ;
}
QNO2: Write a program that asks the user to input 3 numbers now determine
which number is greater and print the result.
#include<iostream>
#include<math.h>
int main()
int n1,n2,n3;
cin>>n1;
cin>>n2;
cin>>n3;
int Max=n1;
if(Max<n2)
Max=n2;
if (Max<n3)
Max=n3;
cout<<"Max is"<<Max<<endl;
return 0 ;
}
QNO3: Write a program that accepts a value from the user, program find the
absolute value (Positive) of a number entered by the user.
#include<iostream>
#include<math.h>
int main()
int a;
cout<<"enter a value"<<endl;
cin>>a;
if (a>0)
else
return 0 ;
QNO4:Write a program that asks the user to input time if user enters negative
time the program should output/print an error and exit.
#include<iostream>
#include<math.h>
int main()
int time;
cout<<"enter time"<<endl;
cin>>time;
if (time>0)
cout<<"time is"<<time;
else
return 0 ;
QNO5: Write a program that inputs 2 numbers from the user and display
message if 2nd number is square of 1 no.
#include<iostream>
#include<math.h>
int main()
int n1,n2;
cin>>n2;
if (n1*n1==n2)
return 0 ;
QNO6: Write a program to calculate the total expenses. Quantity and price
per item are input by the user and a discount of 10% is offered if the expense
is more than 5000.
#include<iostream>
#include<math.h>
int main()
int a,b,t,td,tp;
float d;
d=0.10;
cin>>a;
cin>>b;
t=a*b;
td=t*d;
tp=t-td;
if (t>5000)
return 0 ;
QNO7: Write a program that inputs the name and 3 subject's marks from the
user, and calculate the marks average if the average is above 80 then the
program display message you are outstanding.
#include<iostream>
#include<math.h>
int main()
float average;
cin>>marks;
average=marks%100;
if (marks>80)
QNO8: Write a program that inputs a year from the user and displays the
entered year is a Leap year or not.
#include<iostream>
#include<math.h>
int main()
int year;
cout<<"enter a year"<<endl;
cin>>year;
if (year%4==0)
else
return 0 ;
QNO9: Any integer is input by the user. Write a program to find out whether
it is an odd number or even number.
#include<iostream>
#include<math.h>
int main()
int numb,odd,even;
cout<<"enter a number"<<endl;
cin>>numb;
if (numb%2 == 0)
cout<<numb<<"numb is even"<<endl;
else
cout<<numb<<"numb is odd"<<endl;
return 0 ;
#include<iostream>
#include<math.h>
int main()
int num;
cout<<"enter a number"<<endl;
cin>>num;
else
return 0 ;
QNO11: Write a program that inputs the name age of three persons, If the
ages of Ali, Kashif and Aslam are input by the user than determine and
display the youngest of the them.
#include<iostream>
#include<math.h>
int main()
cin>>Ali;
cin>>Kashif;
cin>>Aslam;
{
if (Ali<Aslam and Ali<Kashif)
}else is
return 0 ;
#include<iostream>
#include<stdlib.h>
int main()
int no;
cout<<"Enter No ";
cin>>no;
int d1, d2, d3;
d1 = no;
d3 = d1%10; ///1
d1 = d1/10; /// 37
d2 = d1%10; ///7
d1 = d1/10; /// 3
else
return 0;
QNO13:
Write a program to check whether a triangle is valid or not, when the three
angles of the triangle are entered by the user. A triangle is valid if the sum of
all the three angles is equal to 180 degrees.
#include<iostream>
int main()
{
float angle1,angle2, angle3;
cin>>angle1;
cin>>angle2;
cin>>angle3;
if (angle1+angle2+angle3 ==180)
else
return 0;
QNO14:
Write a program to determine whether the seller has made profit or incurred
loss. Also determine how much profit he made or loss he incurred. Cost price
and selling price of an item is input by the user.
#include<iostream>
int main()
{
cin>>costprice;
cin>>sellprice;
float profit,loss;
profit=sellprice-costprice;
loss=costprice-sellprice;
if (costprice>sellprice)
else
return 0;
QNO15: Write a program that inputs salary and grade. It adds 70% bonus if
the grade is greater than 17.it adds 25% bonus if the grade is 17 or less and
then display the total salary.
#include<iostream>
cin>>salary;
cin>>grade;
totalsalary=salary+bonus;
if (grade>17)
bonus=salary*(70/100.0f);
if (grade<17)
bonus=salary*(25/100.0f);
totalsalary=salary+bonus;
return 0;
#include<iostream>
int main()
int basicsalry,grosssalry;
cin>>basicsalry;
char hra,da;
if (basicsalry<=10000)
{hra=basicsalry*0.2;
da=basicsalry*0.8;}
if (basicsalry<=20000)
{hra=basicsalry*0.25;
da=basicsalry*0.90;}
else
hra=basicsalry*0.30;
basicsalry*0.95;
grosssalry=basicsalry+hra+da;
return 0;
}
QNO17: Write a C program to input any alphabet and check whether it is
vowel or consonant.
#include<iostream>
int main()
char ch,v,cons;
cin>>ch;
else
return 0;
QNO18: Write a program to calculate the monthly telephone bills as per the
following rule:
Plus Rs. 0.40 per call for any call beyond 200 calls.
#include<iostream>
int main()
int calls,bill;
cin>>calls;
bill= 200;
bill=200+(calls-100)*0.60;
bill=200+0.60*50+(calls-150)*0.50;
else
bill=200+0.60*50+0.50*50+(calls-120)*0.40;
return 0;
}
QNO19: Write a program that determines a student's grade. The program
will read three types of scores (quiz, mid-term, and final scores) and
determine the grade based on the following rules:
#include<iostream>
int main()
cin>>quiz;
cin>>mids;
cin>>finals;
avg=(quiz+mids+finals)/3.0f;
if (avg>=90)
if (avg<50)
return 0;
#include<iostream>
int main()
float percentage;
cin>>eng;
cin>>ict;
cin>>phy;
cin>>chem;
percentage = (eng+maths+ict+phy+chem)/500.0f*100;
cout<<"percentage is"<<percentage<<endl;
if (percentage>=60)
if (percentage<40)
return 0;
QNO21: Write a program that calculates the electricity bill. The rate of
electricity per unit as follows.
• If the units consumed are <=100, then the cost is Rs. 5.5/- per unit. • If the
units consumed are <100 and <=250, then the cost is Rs. 7.5/- per unit.
⚫ If the units consumed exceed <250, then the cost is Rs. 10.5/- per unit.
A line rent Rs. 50 is also added to the bill and surcharge of 7% extra if the bill
exceeded Rs.1500/-.calculate the total bill.
#include<iostream>
int main()
float bill,totbill,units,linerent=50;
cin>>units;
if (units<=100)
bill=units*5.5;
{bill=units*7.5;
if (units>250)
{bill=units*10.5;
if (bill>1500)
{totbill=bill+linerent+(7/100.0f);
}
else
totbill=bill;
return 0;
QNO22: Write a program that displays the following menu for a parking area.
The program inputs the type of vehicle and number of days to park the
vehicle. It finally displays the total charges for the parking according to the
following.
#include<iostream>
int main()
char ch;
int days,rent;
cin>>ch;
cin>>days;
if(ch=='B')
rent=days*300;
else if(ch=='C')
rent=days*600;
else if(ch=='T')
rent=days*900;
return 0;
int main()
char ch;
cin>>ch;
cout<<"character is a digit"<<endl;
return 0;
}
THE END.