Computer Science, asked by aliviaislam49, 4 months ago

s= 8+64+216+512.....N
Write a program in QBasic to solve this problem with For loop​

Answers

Answered by maheshwaranmani2006
0

Explanation:

Given series 0, 8, 64, 216, 512, 1000, 1728, … can also be written as 0 * (02), 2 * (22), 4 * (42), 6 * (62), 8 * (82), 10 * (102), …

Observe that 0, 2, 4, 6, 10, … is in AP and the nth term of this series can be found using the formula term = a1 + (n – 1) * d where a1 is the first term, n is the term position and d is the common difference.

To get the term in the original series, term = term * (term2) i.e. term3.

Finally print the term.

Below is the implementation of the above approach:

C++

// C++ implementation of the approach

#include <bits/stdc++.h>

using namespace std;

  

// Function to return the nth term of the given series

long term(int n)

{

    // Common difference

    int d = 2;

  

    // First term

    int a1 = 0;

  

    // nth term

    int An = a1 + (n - 1) * d;

  

    // nth term of the given series

    An = pow(An, 3);

    return An;

}

  

// Driver code

int main()

{

    int n = 5;

  

    cout << term(n);

  

    return 0;

Similar questions