这题C语言怎么做,要求太高了😓😓😓?
2个回答
展开全部
#include <stdio.h>
int main(void) {
int i=1, flag=1,n=0;
double sum=0;
printf("Input N=");
scanf("%d",&n);
/*while*/
while(i<=100) {
sum+=1.0*flag*n/i;
flag*=-1;
i++;
}
printf("1.while= %f\n",sum);
/*do while*/
sum=0;
flag=1;
i=1;
do {
sum+=1.0*flag*n/i;
flag*=-1;
i++;
} while(i<=100);
printf("2.do-while= %f\n",sum);
/*for*/
sum=0;
flag=1;
for(i=1; i<=100; i++) {
sum+=1.0*flag*n/i;
flag*=-1;
}
printf("3.for= %f",sum);
}
int main(void) {
int i=1, flag=1,n=0;
double sum=0;
printf("Input N=");
scanf("%d",&n);
/*while*/
while(i<=100) {
sum+=1.0*flag*n/i;
flag*=-1;
i++;
}
printf("1.while= %f\n",sum);
/*do while*/
sum=0;
flag=1;
i=1;
do {
sum+=1.0*flag*n/i;
flag*=-1;
i++;
} while(i<=100);
printf("2.do-while= %f\n",sum);
/*for*/
sum=0;
flag=1;
for(i=1; i<=100; i++) {
sum+=1.0*flag*n/i;
flag*=-1;
}
printf("3.for= %f",sum);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询