Untitled
raw download clone
TEXT
views 24
,
size 708 b
#include <stdio.h>
#include <string.h>
#include <math.h>

float func1(float a){
    
    return a*a*a*a-2*a+1;
};
float func2(float a,float times,float h){
    
    float sum = 0;
    for(int i=1;i<=times;i++){
        sum += func1(a+i*h);
    }
    return sum;
}
int main ()
{
    float a = 0.0,b = 2.0;
    float e;
    //float answer = 4.4;
    float output = 1000000;
    float h,temp1,temp2;
    int out_N=0;
    scanf("%f",&e);
    for(int N=1;output-4.4>e;N++){
        
        h = (b-a)/N;
        temp1 = (func1(a)+func1(b))/2.0;
        temp2 = func2(a, N-1,h);
        output = h*(temp1+temp2);
        out_N++;
    }
    printf("%d\n",out_N);
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.