Computer Science, asked by palavpraful, 1 year ago

Write a program to find the nth term in this series 0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8

Answers

Answered by SharmaShashtra
2

#include <iostream>  

#include <math.h>  

using namespace std;  

void findNthTerm(int n)  

{    

     

   if (n % 2 == 0) {  

       n = n / 2;  

       n = 2 * (n - 1);  

       cout << n / 2 << endl;  

   }  

     

   else {  

       n = (n / 2) + 1;  

       n = 2 * (n - 1);  

       cout << n << endl;  

   }  

}  

 

int main()  

{  

   int X = 10;  

   findNthTerm(X);  

     

   X = 7;  

   findNthTerm(X);  

     

   return 0;  

}  

The code is in C++


Similar questions