C++ Programs for Practice | C++ Programming Examples

1. Write a program to print “Welcome to C++”.

Solution:

OR

Output:

Welcome to C++

2. Write a C++ program which prints the following saying,

Determination

Dedication and

Devotion

Takes you to

Better heights!

Solution:

Output:

Determination

Dedication and

Devotion

Takes you to

Better heights!

3. Write a program to display the following (double line spacing is required)

WELCOME TO

          C++ PROGRAMMING

INVENTED BY

          Bjarne Stroustrup

Solution:

Output:

WELCOME TO

        C++ PROGRAMMING

INVENTED BY

        Bjarne Stroustrup

4. Write a C++ program to add two numbers.

Solution:

OR

Output:

Result: 80

5. Write a program to add two numbers taking input from user.

Solution:

OR

Output:

Enter 1st number: 4

Enter 2nd number: 6

Result: 10

OR

Output:

Enter two numbers: 20 40

Result: 60

6. Write a program in C++ to swap two numbers.

Solution:

Output:

Enter 2 numbers: 10 20

Before swapping:

n1: 10 n2: 20

After swapping:

n1: 20 n2: 10

7. Write a C++ program to swap two numbers without using third variable.

Solution:

Output:

Enter 2 numbers: 10 20

Before swapping:

n1: 10 n2: 20

After swapping:

n1: 20 n2: 10

8. Write a C++ program to calculate simple interest.

Solution:

Output:

Enter the principal amount: 4000

Enter rate of interest: 4

Enter the number of years: 2

The simple interest is: 320

Leave a Comment