You are on page 1of 5

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:

#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: Write a program. Output is followed

Output

You might also like