Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

C++ Program Examples and Sample Outputs

Rating
-
Sold
-
Pages
4
Uploaded on
28-10-2021
Written in
2020/2021

Learn with C++ Program Examples and Sample Outputs. View in full!

Institution
Course

Content preview

C++ PROGRAM EXAMPLES AND SAMPLE OUTPUTS

For you to develop the skills in formulating c++ programs, try to examine and analyze each program below. It would be
better if you will encode this program on code:block or any c++ compiler apps, then build and run the program for you to
learn how the output will be displayed. If your program displays the same with the result shown below, then you are
successful.. I encourage you then to examine, analyze, encode, test and run the sample programs below.

1. Write a program in C++ to display a welcome text in a separate line.
Sample Solution:
C++ Code : Sample Output:

#include <iostream> Print a welcome text in a separate line:
using namespace std; ----------------------------------------------
Welcome to
int main() w3resource.com
{
cout << "\n\n Print a welcome text in a separate line :\n"; Note:
cout << "----------------------------------------------\n"; *** cout << statement displays text
cout << " Welcome to \n" ; within the double quotation (“ ”)
cout << " w3resource.com "<<endl ; ***\n within the quotation means move
return 0; to the next line
}

or you can just use <<endl before ending the statement instead of \n
#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Print a welcome text in a separate line : " <<endl ;
cout << "----------------------------------------------" <<endl ;
cout << " Welcome to " <<endl ;
cout << " w3resource.com "<<endl ;
return 0;
}

2. Write a program in C++ to display the sum of 29 and 30.

Sample Solution: C++ Code : Sample Output:
#include <iostream> Print the sum of two numbers:
using namespace std; -----------------------------------
The sum of 29 and 30 is : 59
int main()
{
cout << "\n\n Print the sum of two numbers :\n";
cout << "-----------------------------------\n";
cout << " The sum of 29 and 30 is : "<< 29+30 <<"\n\n" ;
}

3. Write a program in C++ to print the sum of 29 and 30 using variables.

Sample Solution: C++ Code : Sample Output:

#include <iostream> Print the sum of two numbers:
using namespace std; -----------------------------------
The sum of 29 and 30 is : 59
Sample Solution:
int main() This is how local
{ variables are declared
C++ Code
cout :
<< "\n\n Print the sum of two numbers :\n";

Written for

Institution
Course

Document information

Uploaded on
October 28, 2021
Number of pages
4
Written in
2020/2021
Type
Class notes
Professor(s)
Nani madriaga
Contains
1

Subjects

$4.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sophiamadriaga

Get to know the seller

Seller avatar
sophiamadriaga
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
9
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions