赞
踩
while写法:
#include<stdio.h> int main() { double sum=0, a=2, b=1, c, term; int i=1; while (i<=20) { term = a/b; sum = sum + term; c = a+b; b = a; a = c; i++; } printf("The sum is: %.2f\n",sum); return 0; }
do-while写法:
#include<stdio.h> int main() { double sum=0, a=2, b=1, c, term; int i=1; do { term = a/b; sum = sum + term; c = a+b; b = a; a = c; i++; } while (i<=20); printf("The sum is: %.2f\n",sum); return 0; }
for写法:
#include<stdio.h> int main() { double sum=0, a=2, b=1, c, term; int i; for(i=1; i<=20; i++) { term = a/b; sum = sum + term; c = a+b; b = a; a = c; } printf("The sum is: %.2f\n",sum); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。