作业5
#include<stdio.h> int main() { int i=1,fh=1; double sum=0,x,fm=0; while(i<=100){ i++; fm=fm+1; x=fh*1/fm; fh=-fh; sum=sum+x; } printf("sum=%lf",sum); return 0; }
#include<stdio.h> int main() { int i=1,fh=1; double sum=0,x,fm=0; do{ i++; fm=fm+1; x=fh*1/fm; fh=-fh; sum=sum+x; }while(i<=100); printf("sum=%f",sum); return 0; }
#include<stdio.h> int main() { int i,fh=1; double sum=0,x,fm=0; for(i=1;i<=100;i++){ fm=fm+1; x=fh*1/fm; fh=-fh; sum=sum+x; } printf("sum=%lf",sum); return 0; }
#include<stdio.h> int main() { double sum1=1,sum2=0,i; while(i<10){ i++; sum1=sum1*i; printf("%.0lf!=%.0lf\n",i,sum1); sum2=sum2+sum1; } printf("1!+2!+...+10!=%.0lf",sum2); return 0; }
#include<stdio.h> int main() { int x1=1,x2=1,i=1; printf("1,1,"); while(i<=4){ i++; x1=x1+x2; x2=x2+x1; printf("%d,%d,",x1,x2); } return 0; }
#include<stdio.h> int main() { int i,x1,x2,x; x1=1,x2=1; printf("%3d%3d",x1,x2); for(i=1;i<=8;i++){ x=x1+x2; printf("%3d",x); x1=x2; x2=x; } return 0; }
#include<stdio.h> int main() { double n,x1,x2,x3,i=1,sum=0,item; printf("Input n:\nn="); scanf("%lf",&n); scanf("%lf%lf",&x1,&x2); while(i<=n){ i++; item=x1/x2; x3=x1; x1=x1+x2; x2=x3; sum=sum+item; } printf("sum=%.2lf",sum); return 0; }
#include<stdio.h> int main() { double sum=0,a,n,i=1,b; printf("Input a,n:"); scanf("%lf%lf",&a,&n); b=a; while(i<=n){ i++; sum=sum+a; a=10*a+b; } printf("sum=%lf",sum); return 0; }