Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

PROGRAM 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:

Here it is the code for for a very simple calculator:

Play with it and try to make it more fun.....

#include <iostream>

using namespace std;

int main()
{
cout << "Welcome To a very Basic calculator"<< endl;

cout << "Enter the first number: ";

int fnum;

cin>> fnum;

cout << "Enter the second number: ";

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;

cin >> input;


if(input==1){

cout<< "Your answer is: "<<fnum+snum;

}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;
}
}

PROGRAM 6: Write a program . Output is follow

Output

PROGRAM:

#include <iostream>
using namespace std;
int main(){
int x,y;
char z;

cout<<"Please Enter 1st Number! = ";


cin>>x;
cout <<x<<endl;

cout<< "Please Enter 2nd Number! = ";


cin>>y;
cout<<y<<endl;

cout<<"Please Select Operation to Perform! ";


cin>>z;
switch (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 << " INPUT THE SECOND DIGIT! \n";


cin >> y;

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 ;
}

You might also like