IF - Else statement
This statement is used to select a true or false value.
Operators in ‘C++’
Arithmetic operators
+ Plus- Minus
* Multiply
/ Divide
% Reminder
Comparison operators
It is used to compare two values== Equal
<> not equal
< less than
> greater than
<= less than and equal to
>= greater than and equal to
Assignment operators
It is used to assign some variable for e.g.a =10
Logic operators
AND
It is used to join two or more conditions
OR
It is used to check one condition from two or more values
NOT
It is used to check the validity of some condition
Increment and decrement operators
Increment
It is used to increase some variable values for e.g
mostly this operators are used in loops
a++
a=a+1
++a
Decrement operators
It is used to decrease the values
a--
a=a-1
--a
Write a program that accept marks of a statement and display pass or fail message
#include<iostream.h>int main()
{
int marks;
cout<<"\n"<<" Enter Your Marks = ";
cin>>marks;
if(marks>=33)
cout<<"\n"<<" PASS ";
else
cout<<"\n"<<" FAIL";
system("pause");
return 0;
}
Write a program that accept an integer and check it for Even or Odd.
#include<iostream.h>
int main(){
int a;
cout<<"\n"<<" Enter a Number = ";
cin>>a;
if(a%2==0)
cout<<"\n"<<" The Number is Even";
else
cout<<"\n"<<" The Number is Odd";
system("pause");
return 0;
}
Write a program that accept two integers and than show a choice to display the result according
#include<iostream.h>
int main()
{
int a,b,c;
cout<<"\n"<<" Enter First Number = ";
cin>>a;
cout<<"\n"<<" Enter Second Number = ";
cin>>b;
cout<<"\n\n";
cout<<"\n 1. Addition";
cout<<"\n 2. Subtraction";
cout<<"\n 3. Multiplication";
cout<<"\n 4. Division";
cout<<"\n\n Enter your choice = ";
cin>>c;
if(c==1)
cout<<"\n\n Sum = "<<a+b;
else if(c==2)
cout<<"\n\n Subtraction = "<<a-b;
else if(c==3)
cout<<"\n\n Multiplication = "<<a*b;
else if(c==4)
cout<<"\n\n Division = "<<a/b;
else
cout<<"\n\n Wrong Operator";
system("pause");
return 0;
}
Write a program to check the grade of marks obtained
#include<iostream.h>int main()
{
float a,b,c;
cout<<"\n"<<" Enter Obtained Marks = ";
cin>>a;
cout<<"\n"<<" Enter Total Marks = ";
cin>>b;
c=(a/b)*100;
cout<<"\n\n Percentage = "<<c;
if(c>=80)
cout<<"\n\n Grade = A+";
else if(c>=70)
cout<<"\n\n Grade = A";
else if(c>=60)
cout<<"\n\n Grade = B";
else if(c>=50)
cout<<"\n\n Grade = C";
else if(c>=40)
cout<<"\n\n PASS";
else
cout<<"\n\n FAIL";
system("pause");
return 0;
}
Switch statement
Same as ( if else)Write a program that accept a lower case alphabets and check at for vowel or not vowel
#include<iostream.h>
int main()
{
char c;
cout<<"\n Enter a Lower Case Alphabets = ";
cin>>c;
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout<<"\n\n Vowels";
break;
default:
cout<<"\n\n not vowel";
}
system("pause");
return 0;
}
Write a program that accept two integers and than show a choice to display the result according
#include<iostream.h>
int main()
{
int a,b,c;
cout<<"\n Enter First Number = ";
cin>>a;
cout<<"\n Enter Second Number = ";
cin>>b;
cout<<"\n\n";
cout<<"\n 1.Addition";
cout<<"\n 2.Subtraction";
cout<<"\n 3.Multiplication";
cout<<"\n 4.Division";
cout<<"\n\n Enter a Choice = ";
cin>>c;
switch (c)
{
case 1:
cout<<"\n\n Sum = "<<a+b;
break;
case 2:
cout<<"\n\n Subtraction = "<<a-b;
break;
case 3:
cout<<"\n\n Multiplication = "<<a*b;
break;
case 4:
cout<<"\n\n Division = "<<a/b;
break;
default:
cout<<"\n\n Wrong Option";
}
system("pause");
return 0;
}
Write a program to check one number is greater to second number or both numbers are equal?
#include<iostream.h>
int main()
{
float a,b;
cout<<"\n Enter First Number = ";
cin>>a;
cout<<"\n Enter Second Number = ";
cin>>b;
if(a>b)
cout<<"\n\n The First Number is Greater";
else if(a<b)
cout<<"\n\n Second number is Greater";
else
cout<<"\n\n Both Numbers are Equal";
system("pause");
return 0;
}
Write a program that can subtract the two numbers?
#include<iostream.h>
int main()
{
int a,b,c;
cout<<"\n Enter First Number = ";
cin>>a;
cout<<"\n Enter Second Number = ";
cin>>b;
c=a;
a=b;
b=c;
cout<<"\n"<<" Subtraction = "<<b-a;
system("pause");
return 0;
}
( if you have any confusion about this article coments here)
1 comments:
Nice..... Keep It Up Bro