Найти сумму ряда - C (СИ) (72767)

Узнай цену своей работы

Формулировка задачи:

составить программы с использованием трех операторов циклической структуры - for, while, do while. си

Решение задачи: «Найти сумму ряда»

textual
Листинг программы
#include <stdio.h>
#include <math.h>
 
int _tmain(int argc, _TCHAR* argv[])
{
 
    int n = 10;
    float i;
    float result = 0;
    printf("input N: " );
    scanf("%d\\n", &n);
 
    /* цикл for */
    for(i = 1; i <= n; i++){
        result += (log(i)-(i*i))/(4+i);
    }
    printf("result: %f\n", result);
    
    /* цикл while */
    i = 1; result = 0;
    while(i <= n){
        result += (log(i)-(i*i))/(4+i);
        i++;
    };
    printf("result: %f\n", result);
 
    /* цикл do while */
    i = 1; result = 0;
    do{
        result += (log(i)-(i*i))/(4+i);
        i++;
 
    } while(i <= n);
    printf("result: %f\n", result);
 
    return 0;
}

Оцени полезность:

15   голосов , оценка 3.933 из 5