KEMBAR78
CPP Programs Code 1 To 5 | PDF
0% found this document useful (0 votes)
12 views2 pages

CPP Programs Code 1 To 5

The document contains five C++ programs demonstrating basic programming concepts. These include printing 'Hello, World!', calculating the sum of two numbers, finding the maximum of two numbers, implementing a simple calculator, and determining if a number is even or odd. Each program is accompanied by its respective code snippet.

Uploaded by

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

CPP Programs Code 1 To 5

The document contains five C++ programs demonstrating basic programming concepts. These include printing 'Hello, World!', calculating the sum of two numbers, finding the maximum of two numbers, implementing a simple calculator, and determining if a number is even or odd. Each program is accompanied by its respective code snippet.

Uploaded by

akashy0944
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Programs with Code (1-5)

1. Hello World
#include <iostream>
using namespace std;

int main() {
cout << "Hello, World!";
return 0;
}

2. Sum of Two Numbers


#include <iostream>
using namespace std;

int main() {
int a, b, sum;
cout << "Enter two numbers: ";
cin >> a >> b;
sum = a + b;
cout << "Sum = " << sum;
return 0;
}

3. Max of Two Numbers


#include <iostream>
using namespace std;

int main() {
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
if (a > b)
cout << a << " is greater.";
else
cout << b << " is greater.";
return 0;
}

4. Simple Calculator
#include <iostream>
using namespace std;

int main() {
char op;
float a, b;
cout << "Enter operator (+, -, *, /): ";
cin >> op;
cout << "Enter two operands: ";
cin >> a >> b;
switch(op) {
case '+': cout << a + b; break;
case '-': cout << a - b; break;
case '*': cout << a * b; break;
case '/': cout << a / b; break;
default: cout << "Invalid operator";
}
return 0;
}

5. Even or Odd
#include <iostream>
using namespace std;

int main() {
int num;
cout << "Enter an integer: ";
cin >> num;
if (num % 2 == 0)
cout << num << " is even.";
else
cout << num << " is odd.";
return 0;
}

You might also like