#include<stdio.h> int fact(int i); int main() { int n,i; double e,num; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++){ num=fact(i); e=e+num; } printf("和为:%.0lf",e); return 0; } int fact(int i) { int sum=1,n,j; for(j=1;j<=i;j++) sum=sum*j; return sum; }
#include<stdio.h> int main() { int m,n; double i,sum=0,num; printf("Input m,n:"); scanf("%d%d",&m,&n); for(i=m;i<=n;i++){ num=i*i+1/i; sum=sum+num; } printf("和为:%.6lf",sum); return 0; }
#include<stdio.h> int main() { int n,fh=1,i; double fm=1,fz=1,sum=0,num; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++){ num=fh*(fz/fm); fh=-fh; fm=fm+2; fz=fz+1; sum=sum+num; } printf("和为:%.2lf",sum); return 0; }
#include<stdio.h> int main() { int a,b,c,d; double sum,p; printf("Input 4 number:"); scanf("%d%d%d%d",&a,&b,&c,&d); sum=a+b+c+d; p=sum/4; printf("和=%.lf 平均值=%.1f",sum,p); return 0; }
#include<stdio.h> int main() { int x; double d; printf("Input x:"); scanf("%d",&x); if(x<=50) d=x*0.53; else d=(x-50)*0.58+50*0.53; printf("电费为:%.1lf",d); return 0; }
#include<stdio.h> #include<math.h> int main() { int i,n; double sum=0,num; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++){ num=sqrt(i); sum=sum+num; } printf("和为:%.2lf",sum); return 0; }