Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Statement
1. Statement:
If statement:
An if statement consists of a Boolean expression
followed by one or more statements.
OR
If statement is a conditional branching statement used to execute a set
of code when the condition is true. This belongs to control structures.
Syntax:
If (condition)
{
Statements
}
If else statement:
An if statement can be followed by an
optional else statement, which executes when the Boolean expression
is false.
OR
If Else statement is a conditional branching statement used to execute a
set of code when the condition is true, otherwise executes the code in
the "else" part. This belongs to Control Structures.
Syntax:
2. If (condition)
{
Statements
}
Else
{
Statements
}
If else if statement:
An if statement can be followed by
an optional else if...else statement, which is very use full to test various
conditions using single if...else if statement.
OR
The if else if statement is an extension of the "if else" conditional
branching statement. When the expression in the "if" condition is
"false" another "if else" construct is used to execute a set statements
based on a expression. This belongs to Control Structures.
Syntax:
If (condition)
{
Statements
3. }
Else if (condition)
{
Statements
}
Else
{
Statements
}
Nested If-Else Statement:
An if statement inside another if
statement is termed as nested statement.
OR
An If statement is inside another if statement is termed as nested if
statement. This type of control structures is called conditional
branching.
Syntax:
if(condition)
{
if (condition)
{
Statements;
}
4. else
{
Statements;
}
}
else
{
Statements;
}
PROGRAMS
1. Write a program to convert a number in words?
Description:
Take a number from user and convert it into words.
Method:
User will enter a number and by using if statement program will convert it in words.
Input:
Enter number
Program:
5. #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A,N,R;
cout<<"Enter Number ";
cin>>A;
N=(A/10);
R=(A-(N*10));
cout<<"n";
if (N==1)
{
cout<<"one";
}
else if (N==2)
{
cout<<"Two";
}
else if (N==3)
{
cout<<"Three";
}
else if (N==5)
{
cout<<"Five";
}
else if (N==6)
{
cout<<"Six";
}
else if (N==7)
{
cout<<"Seven";
}
else if (N==8)
{
cout<<"Eight";
}
else
{
cout<<"Nine";
}
if (R==0)
{
cout<<"zero";
6. else if (N==4)
{
cout<<"Four";
}
else if (R==2)
{
cout<<"Two";
}
cout<<"Two";
}
else if (R==3)
{
cout<<"Three";
}
else if (R==4)
{
cout<<"Four";
}
else if (R==5)
{
cout<<"Five";
}
else if (R==1)
{
cout<<"One";
}
else if (R==6)
{
cout<<"Six";
}
else if (R==7)
{
cout<<"Seven";
}
else if (R==8)
{
cout<<"Eight";
}
else
{
cout<<"Nine";
}
getch();
}
7. }
Output:
2. Write a program to find the youngest of three persons?
Description:
Take ages of three persons from user, and print the youngest of the three.
Method:
User will enter ages of the three persons, program will find the youngest of the three by using if else
if statement.
Input:
Program:
#include<iostream.h>
#include<conio.h>
void main()
if (Ali < Ahmed && Ali < Akram)
{
cout<<"Ali is youngest";
Enter number 23
Two Three
Age of Ali :
Age of Ahmed :
Age of Akram :
8. {
clrscr();
int Ali,Ahmed,Akram;
cout<<"Age of Ali : ";
cin>>Ali;
cout<<"Age of Ahmed : ";
cin>>Ahmed;
cout<<"Age of Akram : ";
cin>>Akram;
cout<<"n";
}
else if (Ahmed < Ali && Ahmed < Akram)
{
cout<<"Ahmed is youngest";
}
else
{
cout<<"Akram is youngest";
}
getch();
}
Output:
Age of Ali : 15
Age of Ahmed : 20
Age of Akram : 18
Ali is Youngest
3. Write a program to calculate the monthly telephone bills as per the following rule:
Minimum Rs. 200 for upto 100 calls.
Plus Rs. 0.60 per call for next 50 calls.
Plus Rs. 0.50 per call for next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.
Description:
Take number of calls from user and print the total bill by calculation costs as per criteris:
Minimum Rs. 200 for upto 100 calls.
Plus Rs. 0.60 per call for next 50 calls.
Plus Rs. 0.50 per call for next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.
Method:
9. User will enter the number of calls, and by using if else if statement program will calculate the total
bill to be paid by customer.
Input:
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int calls;
cout<<"Total number of calls : ";
cin>>calls;
float bill;
cout<<"n";
if (calls<=100)
{
bill=200;
cout<<"Bill is : "<<bill<<" rupees";
}
else if (calls>100 && calls<=150)
{
bill=((calls-100)*0.60)+200;
cout<<"Bill is : "<<bill<<" rupees";
}
else if (calls>150 && calls<=200)
{
bill=((calls-150)*0.50)+(50*0.60)+200;
cout<<"Bill is : "<<bill<<" rupees";
}
else
{
bill=((calls-200)*0.40)+(50*0.50)+(50*0.60)+200;
cout<<"Bill is : "<<bill<<" rupees";
}
getch();
}
Total number of calls :
10. Output:
4. Write a program to find grade of students?
Description:
Take marks of student by user and print the grade student achieved.
Method:
User will enter the grades of the student and program will print the achieved grade of the student by
using if else if statement.
Input:
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int M;
cout<<"Enter student's marks : ";
cin>>M;
cout<<"n";
if (M>=90)
{
else if (M>=70)
{
cout<<"Your grade is { B }";
}
else if (M>=55)
{
cout<<"Your grade is { C }";
}
else if (M>=45)
{
cout<<"Your grade is { D }";
Total number of calls : 195
Bill is : 252.5 rupees
Enter Student’s marks :
11. cout<<"Your grade is { A+ }";
}
else if (M>=80)
{
cout<<"Your grade is { A }";
}
}
else
{
cout<<"You are fail";
}
getch();
}
Output:
5. Write a program to find the greatest of the three numbers entered by user?
Description:
Take three numbers from user and print the greatest one.
Method:
User will enter three numbers and by using if else if statement program will print the greatest number.
Input:
Program:
#include<iostream.h>
#include<conio.h>
cout<<A<<"is Greater";
}
Enter Student’s Marks : 66
Your grade id { C }
Enter 1st number
Enter 2nd number
Enter 3rd number
12. void main()
{
int A,B,C;
cout<<"ENTER 1ST NUMBER ";
cin>>A;
cout<<"ENTER 2ND NUMBER ";
cin>>B;
cout<<"ENTER 3ND NUMBER ";
cin>>C;
if (A>B)
{
if (A>C)
{
else if (B>A)
{
if (B>C)
{
cout<<B<<” is Greater";
}
else
{
cout<<C<<" is Greater";
}
}
}
getch();
}
Output:
Enter 1st number 53
Enter 2nd number 25
Enter 3rd number 35
53 is greater
6. Write a program to find whether the number is prime or not?
Description:
Take a number from user, and tell whether the number is prime or not.
Method:
User will enter a number and by using loop and if else statement program will find whether it is prime
or not.
Input:
13. Enter number :
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int N;
cout<<"Enter number : ";
cin>>N;
int P=1;
for (int i=2; i<=N-1; i++)
{
if (N%i==0)
{
P=0;
}
}
cout<<"n";
if (P==1)
{
cout<<"It is a Prime number";
}
else
{
cout<<"It is not a Prime number";
}
getch();
}
Output:
Enter number : 79
It is a prime number
14. 7. 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?
Description:
Take Cost price and selling price from user and tell how much profit he made or loss he incurred.
Method:
User will enter cost and selling price and program will print how much he has made profit or incurred
loss.
Input:
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int C,S,P,L;
cout<<"Cost Price : ";
cin>>C;
cout<<"Selling Price : ";
P=S-C;
cout<<"Seller has made profit of : "<<P<<"
Rupees";
}
else
{
L=C-S;
cout<<"Seller has incurred Loss of : "<<L<<"
Rupees";
}
Cost Price :
Selling Price :
15. cin>>S;
cout<<"n";
if (S>C)
{
getch();
}
Output:
8. Write a program to determine whether the student is eligible for science group or arts group.
Description:
Take marks of two subjects of a student from user and tell whether the student is eligible for science
group or arts group.
Method:
User will enter the marks of two subjects of a student and program will print whether the student is
eligible for science group or arts group.
Input:
Program:
#include<iostream.h>
#include<conio.h>
else
{
Cost Price : 120
Selling Price : 133
Seller has made profit of: 13 rupees
Mathematics=
English=
16. void main()
{
clrscr();
int M,E;
cout<<"Mathematics=";
cin>>M;
cout<<"English=";
cin>>E;
cout<<"n";
if(M>50)
{
if(E>50)
{
cout<<"Eligible for section A";
}
cout<<"Eligible for Science Group";
}
}
else
{
if(E>50)
{
cout<<"Eligible for Arts Group";
}
else
{
cout<<"Eligible for Section D";
}
}
getch();
}
Output:
Mathematics= 53
English= 52
Eligible for Science group
9. Write a program to find the whether the given dimensions are of square or a rectangle. Also print
is area.
Description:
Take length and width of a shape, and tell whether it is square or a rectangle also print its area.
Method:
17. User will enter the length and width , program will print its area and tell whether it is square or a
rectangle. Using if else statement.
Input:
Enter the number
Enter the number
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int l,w,area;
cout<<”enter the number”;
cin>>l;
cout<<”enter the number”;
cin>>w;
area = l*w;
if(l==w)
{
cout<<”square n”;
cout<<”the area is =”<<area;
}
else
{
cout<<”rectangle n”;
cout<<”the area is =”<<area;
}
getch();
}
Output:
Enter the number 10
Enter the number 20
rectangle
the area is = 200
10. Write a program to check the number is even or odd.
18. Description:
In this program the user enters any number and with the help of conditions we can easily
determine the number is even or odd.
Method:
In this program the user enter any number and by using the conditions we can easily determine the
number is even or odd because if the first condition ifcondition is satisfied then the number is
even otherwise it goes to next else condition which is for odd one.
Input:
Enter Number to check it is Even or Odd: (This message will be displayed 1 time)
#include<iostream>
#include<conio.h>
void main()
{
intNum;
cout<<"Enter Number to check it is Even or Odd:";
cin>>Num;
if(Num%2==0)
{
cout<<"Number is Even";
}
else
{
cout<<" Number is Odd";
}
getch();
}
19. Program:
Output:
11. Write a program that inputs a year and finds whether it is a leap year or
not using if-else structure.
Description:
In this program the user enters
some random year and by using
if-else condition we can find out
the year is leap year or not.
Method:
In this program the user enters some random year and by using the conditions we can easily
determine the number is leap year or not because if the first condition ifcondition is satisfied then
the year is leap otherwise it goes to next else condition which is for not leap year.
Input:
Enter a year: (This message will be displayed 1 time)
Program:
#include<iostream>
#include<conio.h>
void main()
if(Num%4==0)
{
cout<<Num<<”is a leap year”;
Enter Number to check it is Even or Odd: 5
Number is Odd
20. {
intNum;
cout<<"Enter a year:";
cin>>Num;
}
else
{
cout<<Num<<”is not a leap year”;
}
getch();
}
Output:
Enter a year: 2013
2013 is not a leap year
12. Write a program that inputs salary and grade. It adds 50% bonus if the
grade is greater than 15. It adds 25% bonus if the grade is 15 or less and
then displays the total salary.
Description:
In this program the user enters the salary and also his grade and by using if-else condition we can
easily add bonus to the salary by applying condition to the grade as the requirement given in the
program.
Method:
In this program the user enters the salary and grade. By giving condition to the grade of the user
we can easily solve this program that applying if condition of the grade that if the grade is above
15 we can easily add 25% amount to the enter salary and other goes in the elsecondition that
obviously remaining grade is 15 or less than 15 goes to else condition so in that condition we can
easily add 25% amount in the salary.
Input:
Enter your salary (This message will be displayed 1 time)
Enter your grade (This message will be displayed 1 time)
21. Program:
#include<iostream>
#include<conio.h>
void main()
{
Float salary,bonus;
int grade;
cout<<”Enter your salary=”;
cin>>salary;
cout<<”Enter your grade=”;
cin>>grade;
if(grade>15)
{
bonus=salary*50.0/100.0;
}
Else
{
bonus=salary*25.0/100.0;
}
salary=salary+bonus;
cout<<”Your total salary is =”<<salary;
getch();
}
Output:
Enter your salary=16000
Enter your grade=17
Your total salary is 24000
13. Write a program that inputs a character and displays whether it is vowel
or not.
Description:
In this program the user enter any character and by using if-else condition we can easily
determine the character is vowel or a consonant.
Method:
In this program the user enter any character and by using if-else condition we can easily determine
the entered character is vowel or consonant, because in the first condition we check the enter
22. character that is vowel and else remaining in the 2nd condition which is else and that is for
consonant determination.
Input:
Enter a character:(This message will be displayed 1 time)
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
char x;
cout<<"Enter a character: ";
cin>>x;
if(x=='a'||x=='A'||x=='e'||x=='E'||x=='I'||x=='I'||x=='o'||
x=='O'||x=='u'||x=='U')
{
cout<<x<<" is a Vowel ";
}
else
{
cout<<x<<" is a consonant ";
}
getch();
}
Output:
Enter a character: b
b is a consonant
14. Write a program to check whether a a student have pass or
23. fail, if student pass three subjects he will pass other wise fail, when
the marks of three subjects are entered by the user.
Description:
in this programme we wil find either the student have pass the exam or not .
Method :
The user wil enter the marks of three subjewcts we wil use if else condition to find student
is pass or not , if the marks of individual subjaect is above 50 , pass otherwise fail.
Input:
Enter the marks in math :
Enter the marks in physics :
Enter the marks in urdu:
Program:
#include<iostream.h
#include<conio.h>
void main()
{
int math , physics , urdu;
cout<<":";
cin>>math;
cout<<"Enter the marks in physics :";
cin>>physics;
cout<<"Enter the marks in urdu :";
cin>>urdu;
if( math >50 && physics >50 && urdu
>50)
{
cout<<" you have pass the test";
}
else
{
cout<<" you are fail";
}
getch();
}
24. Output:
Enter the marks in math : 78
Enter the marks in physics : 56
Enter the marks in urdu: 97
you have pass the test
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.
Description:
A triengle is valid the sum of its three angl3 eis equal to 1800 , in this programe we will find the given
triangle is valid or not.
Method :
to find either the triangle is valid or not ,we willl use if else condition ... if sum of three angles
become equql to 1800 then its a triangle otherwise not.
Input:
Enter the angle of triangle angle1:
Enter the angle of triangle angle2:
Enter the angle of triangle angle3:
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
if (angle1+angle2+angle3==180)
{
cout<<"Triangle is valid";
}
25. int angle1,angle2,angle3;
cout<<"Enter the angle of triangle angle1:";
cin>>angle1>>
cout<<"Enter the angle of triangle angle2:";
cin>> angle2;
cout<<"Enter the angle of triangle angle3:";
cin>>angle3;
else
{
cout<<"Triangle is not valid";
}
getch();
}
Output:
Enter the angle of triangle angle1: 60
Enter the angle of triangle angle2: 110
Enter the angle of triangle angle3: 45
Triangle is not valid