2018 885程序设计编程题
-
//定义一个函数,计算并返回如下算式的值 #include <stdio.h> #include <math.h> float fun(int a,int b,int c){ float x=4.25*(a+b)+log(a+b+sqrt(a+b)+1.0/(a+b)); float y=4.25*c+log(c+sqrt(c)+1.0/c); return x/y; } int main(){ FILE *fp; int a,b,c,i=0; if((fp=fopen("data.txt","w+"))==NULL){ printf("cannot open the file.\n"); } while(i<10){ scanf("%d%d%d",&a,&b,&c); printf("a=%d,b=%d,c=%d,result=%f\n",a,b,c,fun(a,b,c)); fprintf(fp,"a=%d,b=%d,c=%d,result=%f\n",a,b,c,fun(a,b,c)); i++; } fclose(fp); return 0; }
-
#include <stdio.h> #include <math.h> int main(){ int n,tem,b,i=0,k=0; int a[100]; int flag=1; printf("please input n:\n"); scanf("%d",&n); tem=n; while(tem>0){ a[i++]=tem%10; tem/=10; } for(b=0;b<i-1;b++){ if(a[b]>a[b+1]) flag=0; } if(flag==1) printf("%d是降序数",n); else printf("%d是非降序数",n); return 0; }
-
#include <stdio.h> #include <math.h> double f(double x){ return pow(x,41)+pow(x,3)+1; } double fd(double x){ return 41*pow(x,40)+3*pow(x,2); } int main(){ float x2=-1,x1=-1,f1,f2; do{ x1=x2; f1=f(x1); f2=fd(x1); x2=x1-f1/f2; }while(fabs(x2-x1)>1e-6); printf("%f",x2); return 0; }
一纸高中万里风,寒窗读破华堂空。
莫道长安花看尽,由来枝叶几相同?