Program to find sum of the series 1 + ( 1 + x ) + ( 1 + x + x^ 2 ) +...n terms.

Write a program to sum of the series  1 + ( 1 + x ) + ( 1 + x + x^ 2 ) +...n terms.

Formula:

Sn=1xn(x1)2x(xn1)

Example:

Input:  n=4, x=2
Output: Sum of series is -34.000000

Approach

C

#include <stdio.h>
#include <math.h>

int main()
{
    int nx;
    printf("Enter value of n: ");
    scanf("%d", &n);

    printf("Enter value of x: ");
    scanf("%d", &x);

    float ans = n / (1 - x) - (x * (pow(xn) - 1)) / (pow(x - 12));

    printf("Sum of series is %f"ans);

    return 0;
}


No comments:

Post a Comment