Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
532 B
2
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
double f4(int n);

int main() {
    int n;
    printf("Enter the number of values:\n");
    scanf("%d", &n);
    printf("Enter %d real numbers:\n", n);
    double sum = f4(n);
    printf("Sum of even positions: %.1lf\n", sum);
    return 0;
}

double f4(int n) {
    double x;
    if (n == 0) {
        return 0;
    }
    scanf("%lf", &x);
    if (n % 2 == 1) {  // change condition to n % 2 == 1
        return x + f4(n - 1);
    }
    else {
        return f4(n - 1);
    }
}