Professional Documents
Culture Documents
Lab Practice 1
Lab Practice 1
#include <iostream>
using namespace std;
int main()
{
int a = 30;
int b = 12;
int sum = a + b;
cout << sum;
return 0;
}
ANS : 42
PROGRAM :2
int main()
{
int a = 30;
int b = 12;
int c = a + b;
cout << c;
return 0;
}
PROGRAM 3:
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout << "Enter a number a\n";
cin >> a;
cout << "Enter number b\n";
cin >> b;
int sum=a+b;
cout <<a<< "+" << b << "=";
cout <<sum;
}
OUTPUT :
#include <iostream>
using namespace std;
int main()
{
int a;
cout <<"Enter a number please\n";
cin>>a;
int b;
cout <<"Enter another number or same number\n";
cin>>b;
int sum
sum =a+b;
cout <<"Sum is " <<sum <<endl;
return 0;
}
PROGRAM 4:
With this code, the program will ask the user to input their age.
#include <iostream>
using namespace std;
int main()
{
int age;
cout << "Please enter your age \n";
cin >> age;
if (age > 14) {
if(age >= 18) {
cout << "Adult";
}
else {
cout << "Teenager";
}
}
else {
if (age > 0) {
cout << "Child";
}
else {
cout << "Something's wrong";
}
}
return 0;
}
PROGRAM 5:
#include <iostream>
int main()
{
cout << "Welcome To a very Basic calculator"<< endl;
int fnum;
cin>> fnum;
int snum;
cin>> snum;
cout<< "\nIf you want to \n Add the numbers Press 1 \n Press 2 to multiply \n Press 3 to divide\n
Press 4 to minus ";
int input;
}else if(input==2){
cout<< "Your answer is: "<<fnum*snum;
}else if(input==3){
cout<< "Your answer is: "<<fnum/snum;
}else if(input==4){
cout<< "Your answer is: "<<fnum-snum;
}
}
Output
PROGRAM:
#include <iostream>
using namespace std;
int main(){
int x,y;
char z;
case '+' :
cout<< "\n + Addition\n";
cout<< " your result is "<< x+y <<endl;
break ;
case '-' :
cout<<"\n - Subtraction \n";
cout <<"your result is "<<x-y <<endl;
break;
case '*' :
cout << " \n * Multiplication \n ";
cout << "your result is "<<x*y <<endl;
break ;
case '/' :
cout<< " \n / Division \n";
cout << "your result is "<<x/y <<endl;
break ;
case '%' :
cout<< " \n % Modulus \n";
cout<< "your result is "<<x%y <<endl;
break;
}
return 0;
}
PROGRAM 6:
#include <iostream>
using namespace std;
int main()
{
int x = 10 * 2;
int y = 10 + 10;
int z = 10 - 5;
int a = 10 / 2;
int b = 10 % 1;
int sum;
sum << x+y+z+a+b;
cout << "Result is \n";
cout << x+y+z+a+b;
return 0;
}
//Output is 50
PROGRAM 7:
#include <iostream>
using namespace std;
int main()
{
int a, b, pro=a*b;
cout << "Enter a number \n";
cin >> a; cout << a <<endl;
cout << "Enter another number \n";
cin >> b; cout << b << endl;
cout << "The product is \n";
cout << pro;
return 0;
}
PROGRAM 8:
#include <iostream>
using namespace std;
int main()
{
int x, y;
char z;
cout << " INPUT THE FIRST DIGIT! \n ";
cin >> x;
cout << " WHICH OPERATION WILL YOU LIKE TO PERFORM? (+,-,*,/,%)\n";
cin >> z;
switch (z) {
case '+' :
cout << "THE RESULT IS:" << x + y <<endl;
break;
case '/' :
cout << "THE RESULT IS:" << x / y <<endl;
break;
case '*' :
cout << "THE RESULT IS:" << x * y <<endl;
break;
case '-' :
cout << "THE RESULT IS::" << x - y << endl;
break;
case '%' :
cout << "THE RESULT IS:" << x % y << endl;
break;
}
return 0 ;
}