PDA

View Full Version : Algorithm


jercee
Oct 15, 2013, 07:21 AM
Write an algorithm to find the first 50 natural numbers

Celine91
Oct 16, 2013, 03:52 PM
A very simple c++ code can be :

#include <iostream>
using namespace std;
int main()
{

for (int i =0; i<49; i ++)
{
cout<<i<<" ";
}

return 0;
}

--------------------------------------------------
if you only want a general algorithm to read the first n natural numbers:

1. Read n
2. Initialize N = 0
3. Calculate N = N+1
4. If N> n-1, stop
5. Write N