The document contains C++ code snippets that demonstrate basic programs to add two numbers and check if a number is positive or negative. It also includes input/output examples of running the programs.
The document contains C++ code snippets that demonstrate basic programs to add two numbers and check if a number is positive or negative. It also includes input/output examples of running the programs.
Subject Code: UEC2312 Staff Name: J. K. Josephine Julina
Subject Title: OOPS And Data Structures Lab Class: III SEM ECE Batch: 2021 – 2025 Academic Year: 2022-2023
//1 a. Sum of two numbers
#include <iostream> using namespace std; int main() { int a, b; cout<<"Enter first number: "; cin>>a; cout<<"Enter second number: "; cin>>b; cout<<"The sum is "<<a+b; return 0; }
Enter first number: 78
Enter second number: 56 The sum is 134
//1 b. Positive or negative
#include <iostream> using namespace std; int main() { int a; cout<<"Enter a number: "; cin>>a; while(a!=0) { if(a<0) cout<<a<<" is a negative number"; else cout<<a<<" is a positive number"; a=0; } return 0; }