Computer Science, asked by sriharshaparsa27, 11 months ago

Write a program to generate the following series 0,2,8,14,...,34.

Answers

Answered by bhargav85528552
5

Explanation:

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

    int n,i,pr;

    cout<<"Enter the range of number(Limit):";

    cin>>n;

    for(i=1;i<=n;i++)

    {

        pr=0;

       if(i%2==0)

        {

            pr=pow(i,2)-2;

            cout<<pr<<" ";

        }

        else

        {

            pr=pow(i,2)-1;

            cout<<pr<<" ";

        }

    }

}

Answered by Agastya0606
0

C program to print the series 0,2,8,14,..34.

#include<stdio.h>

#include<math.h>

int main()

{

   int n,i,pr;

   printf("Enter the range of number(Limit):");

   scanf("%d",&n);

   for(i=1;i<=n;i++)

   {

       pr=0;

      if(i%2==0)

       {

           pr=pow(i,2)-2;

           printf("%d ",pr);

       }

       else

       {

           pr=pow(i,2)-1;

           printf("%d ",pr);

       }

   }

}

  • In this program two header files are included that are conio.h and math.h.
  • Then some variables are declared and a for loop is used with suitable conditions.
  • The output of co-de will be the required series.
Similar questions