#include <stdio.h>
int sumnum(int,int);
int pingfang(int,int);
float fenshu(int);
int main(int argc,int *argv[])
{
double result = 0;
int temp;
float temp_float;
temp = sumnum(1,100);
printf("1+2+3+...+100 = %d\n",temp);
result += temp;
temp = pingfang(1,50);
printf("1*1 + 2*2 + 3*3 +...+50*50 = %d\n",temp);
result += temp;
temp_float = fenshu(10);
printf("1/1 + 1/2 +1/3 +...+1/10=%f\n",temp_float);
result += temp_float;
printf("the result is :%f\n",result);
system("pause");
return 0;
}
int sumnum(int begin,int end)
{
int i,result = 0;
for (i = begin; i <= end; i++)
{
result += i;
}
return result;
}
int pingfang(int begin,int end)
{
int i,result = 0;
for(i = begin; i <= end; i++)
{
result += i * i;
}
return result;
}
float fenshu(int end)
{
int i;
float result = 0;
for (i = 1; i <= end; i++)
{
result += 1.0 / i;
}
return result;
}
|