#include"stdio.h"
#include"string.h"
#include"conio.h"
#include"windows.h"
#include"math.h"
int f ( int );
int sum ( int );
int main()
{
int a,b;
printf("输入一个整数:");scanf("%d",&a);
b = sum ( a );
printf(" a = %d \t b = %d \n",a,b);
return 0;
}
int sum ( int n )
{
int x;
int s = 0;
for ( x = 0; x <= n; x ++ )
{
s += f ( x );
}
return s;
}
int f ( int z )
{
return z*z+1;
}
请讲解一下答案是怎么算出来的?
输入 a = 3; 得出 b = 18;
每一步是怎么循环的?
能把过程写下来吗?
x的值从0到n x*x+1 所有结果的和
a=3
a=0 带入 x*x+1=1 b=1
a=1 带入 x*x+1=2 b=b+2 b=3
a=2 带入 x*x+1=5 b=b+5 b=8
a=3 带入 x*x+1=10 b=b+10 b=18