You are on page 1of 3

SIMPLE C++ PROGRAMS-1

SHYAM SUNDAR.D

3122 21 3002 098

ADDITION OF TWO NUMBERS

DATE: 06.10.2022

EX.NO:1a

Aim:
To write a C++ program to add two numbers

Program:
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter the first number:";
cin>>a;
cout<<"Enter the second number:";
cin>>b;
c=a+b;
cout<<"The sum is:"<<c;
return 0;
}

Output:
Enter the first number:2
Enter the second number:3
The sum is:5
SHYAM SUNDAR.D

3122 21 3002 098

Result:
Thus, the program to add two numbers is executed and the output is verified.

CHECKING IF AN INTEGER IS POSITIVE OR


NEGATIVE

DATE: 06/10/2022

EX.NO : 1b)

Aim:
To write a C++ program to check whether the given number is positive or negative

Program:
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter the number:";
cin>>a;
if(a==0)
{
cout<<"The number is zero";

}
else if(a>0)
{
cout<<"The number is positive";
}
SHYAM SUNDAR.D

3122 21 3002 098

else
{
cout<<"The number is negative";
}
return 0;
}

Output:
Enter the number:5
The number is positive
Enter the number:-5
The number is negative
Enter the number:0
The number is zero

Result:
Thus the program to check whether an integer is positive or negative is executed and the output is
verified

You might also like