Flowchart of Sum of the first 10 natural numbers program by do-while loop

C++ program of Sum of the first 10 natural numbers by using do-while loop
Let us see the C++ program of Sum of the first 10 natural numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> using namespace std; int main() { int n,sum; sum=0; n=1; do { cout<<n; sum=sum+n; n++; } while(n<=10); cout<<" The sum of the first 10 natural numbers is?"<< sum; } |
Dry Run Explanation with SMT(Shamil’s Memory Table)



Flowchart of Sum of the first 10 natural numbers program using while loop

C++ program to find the Sum of the 1st ten natural numbers using while loop
Let us see the C++ program to find the Sum of the 1st ten natural numbers with the help of a while loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> using namespace std; int main() { int j, sum = 0; cout<<"The first 10 natural number are:\n"; j=1; while(j<=10) { sum = sum + j; cout<<" "<<j; j++; } cout<<"\nThe Sum is : "<< sum; } |
C++ Sum of the 1st ten natural numbers using for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream> using namespace std; int main() { int loop,Sum=0; cout << "\n\n Please! Find the first 10 natural numbers:\n"; cout << " The natural numbers are: \n"; for (loop = 1; loop <= 10; loop++) { cout << loop << " "; Sum=Sum+loop; } cout << "\n The Sum of first 10 natural numbers: "<<Sum << endl; } |
Declarations Flow table (DFT) of Sum of the first 10 natural numbers program in C++.
Let us see the DFT of the above program.Variable | Declaration (Line Number) | Initialization (Line Number) | Use (Line Number) |
sum | 5 | 5,10 | 14 |
j | 5 | 7,12 | 11 |
Sum first 100 Odd natural numbers
Write a program in c++ to find the sum of the first 100 odd natural numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> using namespace std; int main() { int n,sum; sum=0; n=1; do { cout<<n; if(n%2!=0) { sum=sum+n; } n++; } while(n<=100); cout<<" The sum of the first 100 odd natural numbers is?"<< sum; } |
Sum first 1000 even natural numbers
Write a program in c++ to find the sum of the first 1000 even natural numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> using namespace std; int main() { int n,sum; sum=0; n=1; do { cout<<n; if(n%2==0) { sum=sum+n; } n++; } while(n<=1000); cout<<" The sum of the first 1000 even natural numbers is?"<< sum; } |
