Program in C++ to display the n terms of even natural number and their sum

Last modified on May 8th, 2020 Download This Tutorial in PDF

Write a program in C++ to display the n terms of even natural number and their sum.

Flowchart of n terms of even natural number and display their sum

Flowchart of C++ Program to display the n terms of even natural number and their sum

C++ Source Code Of program of displaying the n terms of even natural number and their sum

Output

Input number of terms: 5

the even numbers are:2

4

6

8

10

The sum of numbers up to 5 terms is: 30

Excercise

Find the possible mistakes in the following Shamil’s Flow Table of the program of displaying the n terms of even natural number and their sum.

Suppose user enter 5

Loop What lines will execute? Actual work to do
1 time

J=1

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 Sum += 2*j

Sum+=2*1;

Sum+=2

2 time

J=2

 

1,2,3,4,5,6,7,8,9,(10,11,12,13,14,15,16)2,17 Sum += 2*j

Sum+=2*2;

Sum+=6

3 time

 

J=3

1,2,3,4,5,6,7,8,9,(10,11,12,13,14,15,16)3,17 6+=6

Sum=12

4 time

 

J=4

1,2,3,4,5,6,7,8,9,(10,11,12,13,14,15,16)4,17 12+=8

Sum=20

5 time

 

J=5

1,2,3,4,5,6,7,8,9,(10,11,12,13,14,15,16)5,17 20+=10

Sum=30

 

If user enter num =0 loop still loop will execute one time

Loop What lines will execute? Actual work to do
1 time

J=1

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 Sum=2

Video Lecture

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)