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

C++ Simple Programs

The document contains multiple C++ code examples demonstrating basic programming concepts. It includes examples for printing strings, displaying multiple strings, and adding two numbers. Additionally, it shows how to create and call a function in C++.
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)
21 views3 pages

C++ Simple Programs

The document contains multiple C++ code examples demonstrating basic programming concepts. It includes examples for printing strings, displaying multiple strings, and adding two numbers. Additionally, it shows how to create and call a function in C++.
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

Try Yourself:

[Link] strings

#include <iostream>
using namespace std;

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

[Link] string

#include <iostream>
using namespace std;

int main() {
cout << "Hello World!";
cout << "I am learning C++";
return 0;
}

[Link] of two numbers:

#include <iostream>
using namespace std;

int main() {
int x = 5;
int y = 6;
int sum = x + y;
cout << sum;
return 0;
}
#include <iostream>
using namespace std;

int main() {
int x = 5, y = 6, z = 50;
cout << x + y + z;
return 0;
}

#include <iostream>
using namespace std;

int main() {

int first_number, second_number, sum;

cout << "Enter two integers: ";


cin >> first_number >> second_number;

// sum of two numbers in stored in variable sumOfTwoNumbers


sum = first_number + second_number;

// prints sum
cout << first_number << " + " << second_number << " = " << sum;

return 0;
}
include <iostream>
using namespace std;

// declaring a function
void greet() {
cout << "Hello there!";
}

int main() {

// calling the function


greet();

return 0;
}

You might also like