Computer Science, asked by Rashmi6560, 11 months ago

Can u plz explain in detail the computer program of printing the series 0,3,8,15..

Answers

Answered by sswaraj04
0

Answer:

#include <iostream>

using namespace std;

int main()

{

   int i=0,diff=3,num=10;

   for(int j=1;j<=num;j++)

   {

    cout<<i<<" ";

    i+=diff;

    diff+=2;

   }

   return 0;

}

Explanation:

It's written in c++

FIrst analyse the series

We can see that difference is increasing by 2 each time

3 - 0 = 3

8 - 3 = 5

15 - 8 = 7

so on...

So we initialize a variable with 0(here, 'i' ) which is first term.

Now num stores number of terms of we want to print (here, i took 10 terms)

Now we need a variable for difference (here, 'diff')

and we started loop to execute n no. of times

and incrementing the difference by 2 each time loop executes and summing it to 'i' each time and print it

Hope it helps :-)

Similar questions