Write a C program for the Series Calculation.

Function Main
    Declare Integer n, m, i, j
    Declare Real s, u
    Output "Enter a number of terms to calculate:"
    Input m
    Output "Enter First term index:"
    Input n
    Assign m = INT(( m + 9) / 10)
    Assign s = 0
    For i = 1 to 10
        For j = 1 to m
            Assign u = 1 / n / n
            Assign s = s + u
            Assign n = n + 1
        End
        Output s
    End
End

#include <stdio.h>

int main() {
    int n, m, i, j;
    double s, u;
    printf("Enter a number of terms to calculate:");
    scanf("%d", &m);
    printf("Enter First term index:");
    scanf("%d", &n);
    m = (int) ((double) (m + 9) / 10);
    s = 0;
    for (i = 1; i <= 10; i++) {
        for (j = 1; j <= m; j++) {
            u = (double) 1 / n / n;
            s = s + u;
            n = n + 1;
        }
        printf("%f\n", s);
    }
    return 0;
}

Enter a number of terms to calculate:5
Enter First term index:5
0.040000
0.067778
0.088186
0.103811
0.116157
0.126157
0.134421
0.141366
0.147283
0.152385

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.