"One Way Selection": #Include Using Namespace Int Int
"One Way Selection": #Include Using Namespace Int Int
1: #include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a number:"<<endl;
cin>>num;
if (num>=100)
{
cout<<"the entered number is greater than
100"<<endl;
}
system ("pause");
return 0;
}
“TWO WAY SELECTION”
2: #include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a number:"<<endl;
cin>>num;
if (num>=100)
{
cout<<"the entered number is greater than
100"<<endl;
}
else
cout<<"the entered number is smaller than
100"<<endl;
system ("pause");
return 0;
}
“NESTED IF ELSE”
3: #include<iostream>
using namespace std;
int main()
{
int marks;
system ("pause");
return 0;
}
“SWITCH BREAK OPERATIONS”
4: #include<iostream>
using namespace std;
int main()
{
char grade;
cout<<"Enter the Grade "<<endl;
cin>>grade;
switch (grade)
{
case 'A':
cout<<"Your GPA is 4.00"<<endl;
break;
case'B':
cout<<"Your GPA is 3.00"<<endl;
break;
case 'C':
cout<<"Your GPA is 2.00"<<endl;
break;
case 'D':
cout<<"Your GPA is 1.00"<<endl;
break;
case'F':
cout<<"You are failed"<<endl;
break;
default:
cout<<"Invalid Entry"<<endl;
}
system ("pause");
return 0;
}
WHILE LOOP
5: #include<iostream>
using namespace std;
int main()
{
int i;
i=0;
while(i<20)
{
cout<<"The value of i is :"<<i<<endl;
i=i+5;
}
system ("pause");
return 0;
}
WHILE LOOP
6:
#include<iostream>
int main()
{
int num,sum,avg,count;
sum=0;
count=0;
while (count<5)
{
cout<<"Enter the number :"<<endl;
cin>>num;
sum=sum+num;
count ++;
}
cout<<"The sum of entered numbers is:"<<sum<<endl;
avg=sum/5;
cout<<"The average is:"<<avg <<endl;
system ("pause");
return 0;
}
int main()
{
int num,sum;
sum=0;
char ch;
do
{
cout<<"Enter the number:"<<endl;
cin>>num;
sum=sum+num;
system ("pause");
return 0;
}
“FOR LOOP”
8: #include<iostream>
using namespace std;
int main()
{
int i;
for(i=0;i<10;i++)
{
cout<<"HELLO!!!!"<<endl;
cout<<"*********"<<endl;
}
system ("pause");
return 0;}
“FOR LOOP”
9:
#include<iostream>
int main()
{
int i;
for(i=0;i<10;i++)
{
cout<<i*i<<endl;
}
system ("pause");
return 0;
}
Lab report
#include<iostream>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{
int a, b;
char x;
cout << "enter the first number:" << endl;
cin >> a;
cout << "Enter the operation (+,-,*,/) " << endl;
cin >> x;
cout << "enter the second number:" << endl;
cin >> b;
switch (x)
{
case '+':
cout << "ADDITION : " << a + b << endl;
break;
case '-':
cout << "SUBTRACTION : " << a - b << endl;
break;
case '*':
cout << "MULTIPLACTION : " << a * b << endl;
break;
case '/':
{
if (b == 0)
cout << "MATH ERROR " << endl;
else
QUESTION NO 2:
ANSWER:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int roll;
cout<<"enter the roll numbver : "<<endl;
cin>>roll;
if (roll<=100)
{
switch(roll)
{
case 13:
cout<<"you got 1st position "<<endl;
break;
case 23:
cout<<"you got 2nd position "<<endl;
break;
case 55:
cout<<"you got 3rd position "<<endl;
break;
case 87:
cout<<"you got 4th position "<<endl;
break;
case 93:
cout<<"you got 5th position "<<endl;
break;
default:
cout<<"sorry no position obtained "<<endl;
break;
}
}
else
cout<<"the program is invalid "<<endl;
getch();
}
QUESTION NO 3:
ANSWER:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int scale;
double temperature;
cout<<"\n Type 1 to convert fahrenheit to celsius"<<"\n
Type 2 to convert celsius to fahrenheit"<<endl;
cin>>scale;
if (scale==1)
{
cout<<"enter temperature in fahrenheit : "<<endl;
cin>>temperature ;
cout<<"in celsius :" <<5.0/9.0*(temperature -
32.0 );
}
else
QUESTION NO 4:
ANSWER:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int amount,year,a;
float interest_rate,amount1;
cout<<"Enter the initial amount:";
cin>>amount;
cout<<"Enter the number of year:";
cin>>year;
cout<<"Enter the interest rate:";
cin>>interest_rate;
for(a=1;a<=year;a=a+1)
{
amount1=amount+
(amount*(interest_rate/100));
cout<<"At the end of "<< a<< "
year:"<<amount1<<" dollar "<<"\n";
amount=amount1;
}
cout<<"At the end of "<<year<<"
year"<<",you will have " <<amount1<<" dollars"; getch();
}
QUESTION NO 5:
ANSWER:
#include <iostream>
#include<conio.h>
using namespace std;
void main()
{
int n;
int factorial = 1;
cout << "Factorial of " << n << " = " << factorial;
getch();
}