SlideShare una empresa de Scribd logo
1 de 25
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:
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
} 
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; 
}
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:
#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";
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(); 
}
} 
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 :
{ 
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:
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 :
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 :
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
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:
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
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 :
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=
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:
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.
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(); 
}
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
{ 
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)
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
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
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(); 
}
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"; 
}
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

Más contenido relacionado

La actualidad más candente

C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
Amit Kapoor
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 

La actualidad más candente (19)

Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
C important questions
C important questionsC important questions
C important questions
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
C++ project
C++ projectC++ project
C++ project
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.com
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework Help
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
 

Similar a Statement

Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
Rajeev Sharan
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
Warui Maina
 

Similar a Statement (20)

C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
10 template code program
10 template code program10 template code program
10 template code program
 
C++ file
C++ fileC++ file
C++ file
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Pointer
PointerPointer
Pointer
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdf
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
Project in programming
Project in programmingProject in programming
Project in programming
 

Último

Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
ZurliaSoop
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Hung Le
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
David Celestin
 

Último (17)

in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptx
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
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