Lab 4
Lab 4
LAB REPORT #4
#include<iostream>
#include<string>
using namespace std;
int main()
{
char s;
int a, b ,c;
cout << " ENTER VALUE OF a" << endl;
cin >> a ;
cout << " ENTER VALUE OF b" << endl;
cin >> b;
cout << "ENTER A OPREATION THAT YOU WANT TO PERFORM" << endl;;
cin >> s;
switch (s)
{
case '+' :
cout << "REQUIRED ANSWER" << endl;
cout << a + b;
break;
case '-':
cout << "REQUIRED ANSWER" << endl;
cout << a - b;
break;
case '*':
cout << a * b;
cout << "REQUIRED ANSWER" << endl;
break;
case '/':
cout << "REQUIRED ANSWER" << endl;
cout << a / b;
break;
case '%' :
cout << "REQUIRED ANSWER" << endl;
cout << a % b ;
break;
default :
cout << "Please Select Valid Operator" << endl;
}
}
RESULT ON SECREEN
QNO.02 Correct the following program who prints a sterick sign (*) in such a
way using nested while loops.
ASSINGED PROGRAM
#include <iostream>
using namespace std;
int main()
{
int i = 15, j = 15;
while (i > 0)
{
j = i - 1;
while (j > 0)
{
cout << "*";
j = j - 1;
}
cout << "\n";
i = i - 1;
}
system("pause");
return 0;
}
RESULT ON SECREEN
#include <iostream>
using namespace std;
int main()
{
int i = 1;
int l = 1;
while (i <= 10)
{
int r = 1;
while (r <=l )
{
cout << l;
if (l > 1)
{
cout << "==";
}
l--;
r++;
}
l = i + 1;
cout << "\n";
i++;
}
system("pause");
return 0;
}
QNO.3 A program to show the following using the nested while loop
ASSINGED PROGRAM :
RESULTS ON SECREEN :
#include <iostream>
using namespace std;
int main()
{
int i = 1;
int l = 1;
while (i <= 10)
{
int r = 1;
while (r <=l )
{
cout << l;
if (l > 1)
{
cout << "==";
}
l--;
r++;
}
l = i + 1;
cout << "\n";
i++;