0% found this document useful (0 votes)
58 views3 pages

Simple C

The document describes two simple C++ programs: 1) A program to add two numbers by taking input from the user, adding the numbers, and outputting the sum. 2) A program to check if a number input by the user is positive, negative, or zero by using if/else statements to compare the number to 0. Both programs take input, perform calculations, and output results to verify the programs are working as expected.

Uploaded by

SHYAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

Simple C

The document describes two simple C++ programs: 1) A program to add two numbers by taking input from the user, adding the numbers, and outputting the sum. 2) A program to check if a number input by the user is positive, negative, or zero by using if/else statements to compare the number to 0. Both programs take input, perform calculations, and output results to verify the programs are working as expected.

Uploaded by

SHYAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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