C++ Program Sum of odd Natural Number
Flowchart of Program of Sum of odd Natural Number
C++ Source code of Sum of odd Natural Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include<iostream> #include <conio.h> using namespace std; int main() { int i=1; int input; int sum=0; cout<<"plz Input number of terms : "; cin>>input; cout<<"The odd numbers are :"; do { cout<<"\t"<<2*i-1; sum+=2*i-1; i++; } while(i<=input); cout<<endl; cout<<"\nThe Sum of odd Natural Number upto "<<input<<" are:"; cout<<sum; getch(); } |
Excercise
Find the possible mistakes in the following Shamil’s Flow Table of the programof Sum of odd Natural Numbers.
Loop
|
condition | What line will execute | What actual will do |
I=1 | True | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | plz Input number of terms : 3
The odd numbers are :Â Â 1
The Sum of odd Natural Number upto 3 are:1 |
I=2 | True
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 13 14 15 16 18 19 20 21 22 23 24 | plz Input number of terms : 3
The odd numbers are :Â Â 1Â 3
The Sum of odd Natural Number upto 3 are:4 |
I=3 | True | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 13 14 15 16 18 19 13 14 15 16 18 19 20 21 22 23 24 | plz Input number of terms : 3
The odd numbers are :Â Â 1Â 3 5
The Sum of odd Natural Number upto 3 are:9 |
I=4 | false | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 | plz Input number of terms : 3
The odd numbers are :Â Â 1Â 3Â 5
The Sum of odd Natural Number upto 3 are:9 |