Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

Simple Programs Set1

The document contains five C++ programs demonstrating basic programming concepts. These include printing 'Hello World', calculating the sum of two numbers, swapping two numbers, finding the largest of two numbers, and checking if a number is even or odd. Each program includes the code and its corresponding output.

Uploaded by

Abhilash Alshi
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)
4 views1 page

Simple Programs Set1

The document contains five C++ programs demonstrating basic programming concepts. These include printing 'Hello World', calculating the sum of two numbers, swapping two numbers, finding the largest of two numbers, and checking if a number is even or odd. Each program includes the code and its corresponding output.

Uploaded by

Abhilash Alshi
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/ 1

1) Hello World Program

#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
Output: Hello World

2) Sum of Two Numbers


#include <iostream>
using namespace std;
int main() {
int a = 5, b = 7;
cout << "Sum = " << (a + b);
return 0;
}
Output: Sum = 12

3) Swap Two Numbers


#include <iostream>
using namespace std;
int main() {
int a = 10, b = 20, temp;
temp = a;
a = b;
b = temp;
cout << "a = " << a << ", b = " << b;
return 0;
}
Output: a = 20, b = 10

4) Largest of Two Numbers


#include <iostream>
using namespace std;
int main() {
int a = 15, b = 25;
if(a > b)
cout << "Largest = " << a;
else
cout << "Largest = " << b;
return 0;
}
Output: Largest = 25

5) Check Even or Odd


#include <iostream>
using namespace std;
int main() {
int n = 11;
if(n % 2 == 0)
cout << "Even";
else
cout << "Odd";
return 0;
}
Output: Odd

You might also like