while语句:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
int i = 1;
double sum = 0.0;
while(i <= 50)
{
sum += 1.0/i;
i++;
}
printf("sum = %lf\n",sum);
return 0;
}
for语句:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
int i;
double sum=0.0;
for(i=1;i<=50;i++)
{
sum += 1.0/i;
}
printf("sum = %lf\n",sum);
}