1、
#include <stdio.h> int main(void) { float x1, sum1 = 0.0; for(x1 = 0.0; x1 <= 1.0; x1 += 0.01) { sum1 += x1; } int i; float sum2 = 0.0; for(i = 1; i <= 100; i++) { sum2 += (i / 100.0); } printf("sum1 = %f | sum2 = %f ", sum1, sum2); return 0; }
2、
#include <stdio.h> int main(void) { int i; float x1 = -0.01, x2, sum1 = 0, sum2 = 0; for(i = 0; i <= 100; i++) { x1 += 0.01; x2 = i / 100.0; sum1 += x1; sum2 += x2; printf("x1 = %f | x2 = %f ", x1, x2); } printf("sum1 = %f | sum2 = %f ", sum1, sum2); return 0; }
3、
#include <stdio.h> int main(void) { int i; float x1, x2, sum1, sum2; x1 = sum1 = sum2 = 0.0; for(i = 0; i <= 100; i++) { x2 = i / 100.0; printf("x1 = %f | x2 = %f ", x1, x2); sum1 += x1; sum2 += x2; x1 += 0.01; } printf("sum1 = %f | sum2 = %f ", sum1, sum2); return 0; }