#include<stdio.h> int main() { int i; double ave,sum; int a[4]; printf("Enter 4 个整数
#include<stdio.h> int main() { int denominator,flag,i,n; double item,sum; printf("Enter n:"); scanf("%d",&n); flag=1; denominator=1; sum=0; for(i=1;i<=n;i++){ item=flag*i*1.0/denominator; sum=sum+item; flag=-flag; denominator=denominator+2; } printf("sum=%f\n",sum); return 0; }
#include<stdio.h> #include<math.h> int main () { int i,n; double y,sum; sum=0; printf ("Enter n:"); scanf("%d",&n); for(i=1;i<=n;i++){ y=sqrt(i); sum=sum+y; } printf("sum=%.2lf\n",sum); return 0; }
:"); sum=0; for(i=0;i<4;i++){ scanf("%d",&a[i]); sum=sum+a[i]; } ave=sum/4; printf("ave=%.1f\n",ave); printf("sum=%.0f\n",sum); return 0; }
#include<stdio.h> #include<math.h> int main() { double x,cost; printf("Enter x:"); scanf("%lf",&x); if(x>0&&x<=50) printf("cost=%.2f\n",cost=0.53*x); else if(x>50) printf("cost=%.2f\n",cost=50*0.53+(x-50)*0.58); else printf("Invalid value!"); return 0; }
#include<stdio.h> int main() { int i,n,m,sum1,sum2; int denominator; double item,sum; printf("Enter m:"); scanf("%d",&m); printf("Enter n:"); scanf("%d",&n); sum=sum1=sum2=0; for(i=m;i<=n;i++){ sum1=sum1+m*m; } for(i=m;i<=n;i++){ item=1.0/denominator; sum2=sum2+item; denominator=denominator+1; } sum=sum1+sum2; printf("Sum of number from %d to %d is %.6lf\n",m,n,sum); return 0; }
第六题,不会。。。。。。。
时间: 2024-11-06 19:28:03