0% found this document useful (0 votes)
8 views2 pages

100 Simple CPP Programs Sample

The document contains five C++ programs demonstrating basic programming concepts. The programs include printing 'Hello, World!', displaying a name, adding two numbers, and swapping two variables both with and without using a third variable. Each program is self-contained with a main function and outputs the result to the console.

Uploaded by

mmohanm2323
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)
8 views2 pages

100 Simple CPP Programs Sample

The document contains five C++ programs demonstrating basic programming concepts. The programs include printing 'Hello, World!', displaying a name, adding two numbers, and swapping two variables both with and without using a third variable. Each program is self-contained with a main function and outputs the result to the console.

Uploaded by

mmohanm2323
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

1.

Hello World
#include <iostream>
using namespace std;

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

2. Print your name


#include <iostream>
using namespace std;

int main() {
cout << "My name is John Doe.";
return 0;
}

3. Add two numbers


#include <iostream>
using namespace std;

int main() {
int a = 5, b = 10, sum;
sum = a + b;
cout << "Sum: " << sum;
return 0;
}

4. Swap using third variable


#include <iostream>
using namespace std;

int main() {
int a = 5, b = 10, temp;
temp = a;
a = b;
b = temp;
cout << "a: " << a << " b: " << b;
return 0;
}

5. Swap without third variable


#include <iostream>
using namespace std;

int main() {
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
cout << "a: " << a << " b: " << b;
return 0;
}

You might also like