Question

In: Computer Science

Given the following series: 1, 2, 5, 26, 677, ….. such that the nth term of...

Given the following series: 1, 2, 5, 26, 677, ….. such that the nth term of the series equals to (n-1)th ^2 +1 and the first term of the series is 1. Write a C program using recursive function named f to compute the nth term. Use for loop to print the values of first n terms in the series. You will take input n from the user.

Example output:

Enter number of terms: *value*

*numbers here*

nth term: *value*

PLEASE DO NOT USE IOSTREAM

Solutions

Expert Solution

Program:

#include <stdio.h>

void f(int number) {
    int i;
    int series;
    printf("First n terms in the series : \n");
    // Loop iterates from 1 and till the number n
    for (i=1; i <= number; i++) {
        if (i == 1) { // condition to check for first term
            series = 1; // Print first term in the series as 1
        } else {
            // Other than first term (n-1)^2 + 1
            series = ((i-1)*(i-1))+1;
        }
        // Prints the series of n terms
        printf("%d\n", series);
    }
    // Prints the nth term
    printf("nth term %d\n", series);
}

int main()
{
    int number;
    // Take input for number of terms from user
    printf("Enter number of terms: ");
    scanf("%d",&number);
    // calling function to print series for n numbers
    f(number);

    return 0;
}

Output:


Related Solutions

Use the following time-series data to answer the given questions. Time Period Value 1 26 2...
Use the following time-series data to answer the given questions. Time Period Value 1 26 2 30 3 57 4 62 5 58 6 65 7 70 8 86 9 101 10 97 a. Develop forecasts for periods 5 through 10 using 4-month moving averages. b. Develop forecasts for periods 5 through 10 using 4-month weighted moving averages. Weight the most recent month by a factor of 4, the previous month by 2, and the other months by 1. c....
1. Find the 100th and the nth term for each of the following sequences. a. 50,90,130,......
1. Find the 100th and the nth term for each of the following sequences. a. 50,90,130,... b. 1,4,16,... c. 7, 74,77,710,... d. 197+7x327, 197+8x327, 197+9x327,... 2. Find the first five terms in sequences with the following nth terms. a. 10n-5 b.2n-1 3. How many terms are there in each of the following sequences? a. 11,15,19,23,...331 b. 59,60,61,62,...459
1.) Find the 100th and the nth term for each of the following sequences. a. 1,3,5,7,......
1.) Find the 100th and the nth term for each of the following sequences. a. 1,3,5,7,... b.70,100,130... c.1,3,9... d.8,84,87,810,... e. 200+6x231, 200+7x231, 200+8x231 2. Find the first five terms in sequences with the following nth terms. a. 2n2+6 b.4n+1 c. 10n-5 d.2n-1
Given the following series, tn = 10tn-1+1 where tn is the current term and tn-1 is...
Given the following series, tn = 10tn-1+1 where tn is the current term and tn-1 is the previous terms. Write a Matlab function, which will receive t n-1 will calculate and return tn. Use a for loop to call the function in (a) and print the first 10 terms computed by tn for n=1,…,10. Assume that t0 = 0. Write a Matlab script that loops until the sum of series is 12345 and display the numbers of terms added to...
For each sequence given below, find a closed formula for an, the nth term of the sequence (assume...
For each sequence given below, find a closed formula for an, the nth term of the sequence (assume the first terms here are always a0) by relating it to another sequence for which you already know the formula. −1,0,7,26,63,124,… an=(n^3)-1 −1,1,7,17,31,49,… an=2n^2-1 0,10,30,60,100,150,..... an=10*((n(n+1))/2) 2,3,6,14,40,152,… an= The first three are correct I can't figure out the last one.
Use the formula for the general term​ (the nth​ term) of an arithmetic sequence to find...
Use the formula for the general term​ (the nth​ term) of an arithmetic sequence to find the sixth term of the sequence with the given first term and common difference. a1 =15; d=7 a6 =
how does 2 = 26 *5 -32 * 4 becomes 26 * 5 + 32 *...
how does 2 = 26 *5 -32 * 4 becomes 26 * 5 + 32 * (-6) = 2
1: Explain the term ‘autoregression’ in a time series regression context. 2. Explain the term ‘autocorrelation’...
1: Explain the term ‘autoregression’ in a time series regression context. 2. Explain the term ‘autocorrelation’ and the problems it creates when using OLS regression in time series data.
1: Explain the term ‘autoregression’ in a time series regression context. 2. Explain the term ‘autocorrelation’...
1: Explain the term ‘autoregression’ in a time series regression context. 2. Explain the term ‘autocorrelation’ and the problems it creates when using OLS regression in time series data.
1. Given the series: ∞∑k=1 2/k(k+2) does this series converge or diverge? converges diverges If the...
1. Given the series: ∞∑k=1 2/k(k+2) does this series converge or diverge? converges diverges If the series converges, find the sum of the series: ∞∑k=1 2/k(k+2)= 2. Given the series: 1+1/4+1/16+1/64+⋯ does this series converge or diverge? diverges converges If the series converges, find the sum of the series: 1+1/4+1/16+1/64+⋯=
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT