实验2
#include printf(\"fahr=%d, celsius=%d\\n\",f, c); return 0; } #include printf(\"celsius=%d, fahr=%d\\n\",c, f); return 0; } #include int math=87,eng=72,comp=93; printf(\"math=%d, eng=%d, comp=%d, average=%d\\n\",math, eng, comp, (math+eng+comp)/3); return 0; } #include b=(n/10)%10; a=n/100; printf(\"整数%d 的个位数字是%d, 十位数字是%d, 百位数字是%d\\n\",n, c, b, a); return 0; } #include printf(\"%d=%d*%d\\n\",y,x,x); printf(\"%d*%d=%d\\n\",x,x,y); return 0; } #include printf(\"Enter x:\"); scanf_s(\"%lf\",&x); if(x!=0){ y=1/x; }else{ y=0; } printf(\"f(%.2f)=%.1f\\n\",x,y); return 0; } #include celsius=5*(fahr-32)/9; printf(\"fahr=%d, celsius=%d\\n\",fahr,celsius); return 0; } #include double money, rate,x=1.0; int i,year; printf(\"Enter money, year and rate:\"); scanf(\"%lf %d %lf\",&money,&year,&rate); for(i=1;i<=year;i++) x=x*(1+rate); printf(\"intrest=%.2f\\n\",money*x-money); return 0; } #include printf(\"Enter x\"); scanf_s(\"%lf\",&x); if(x<0.0) y=pow(x+1,2)+2*x+1/x; else y=sqrt(x); printf(\"f(%.2f)=%.2f\\n\",x,y); return 0; } #include int main(){//2-2-5 double x, y; printf(\"Enter x:\"); scanf_s(\"%lf\",&x); if(x==10) y=1/x; else y=x; printf(\"f(%.2f)=%.1f\\n\",x,y); return 0; } #include printf(\"Enter num1:\"); scanf_s(\"%d\",&x); printf(\"Enter num2:\"); scanf_s(\"%d\",&y); printf(\"%d+%d=%d\\n\",x,y,x+y); printf(\"%d-%d=%d\\n\",x,y,x-y); printf(\"%d*%d=%d\\n\",x,y,x*y); printf(\"%d/%d=%d\\n\",x,y,x/y); printf(\"%d%%d=%d\\n\",x,y,x%y); return 0; } #include for(i=1;i<=100;i++){ sum=sum+i; } printf(\"sum=%d\\n\",sum); return 0; } #include printf(\"Enter m:\"); scanf(\"%d\",&m); for(i=m;i<=100;i++) s=s+i; printf(\"sum=%d\\n\",s); return 0; } #include printf(\"Enter m:\"); scanf(\"%d\",&m); printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=m;i<=n;i++) s=s+1.0/i; printf(\"sum=%f\\n\",s); return 0; } #include double s=0.0; printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=1;i<=n;i++) s=s+1.0/(2*i-1); printf(\"sum=%f\\n\",s); return 0; } #include double s=1.0,t=1.0,sign=1.0; printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=1;i printf(\"sum=%.3f\\n\",s); return 0; } #include double fahr,celsius; printf(\"Enter low:\"); scanf_s(\"%d\",&low); printf(\"Enter uper:\"); scanf_s(\"%d\",&uper); printf(\"fahr celsius\\n\"); for(fahr=low;fahr<=uper;fahr+=2){ celsius=5.0/9.0*(fahr-32.0); printf(\"%3.0f %6.1f\\n\",fahr,celsius); } return 0; } #include double p,sum=0.0; printf(\"Enter m:\"); scanf(\"%d\",&m); printf(\"Enter n:\"); scanf(\"%d\",&n); p=1.0; for(i=1;i<=m;i++) p=p*i; sum=sum+p; p=1.0; for(i=1;i<=n;i++) p=p*i; sum=sum+p; printf(\"sum=%.0f\\n\",sum); return 0; } #include printf(\"Enter x:\"); scanf(\"%d\",&x); printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=1;i<=n;i++) p=p*x; printf(\"%d的%d次方是%.0f\\n\",x, n,p); return 0; } #include int n,i; printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=0;i<=n;i++) printf(\"pow(3,%d)=%.0f\\n\",i,pow(3.0,i)); return 0; } #include for(i=100;i<=1000;i++){ sum+=sqrt(i); } printf(\"sum=%.2f\\n\",sum); return 0; }// return 0; } #include printf(\"Enter x:\"); scanf_s(\"%lf\",&x); if(x==10) y=1/x; else y=x; printf(\"f(%.2f)=%.1f\\n\",x,y); return 0; } #include printf(\"Enter num1:\"); scanf_s(\"%d\",&x); printf(\"Enter num2:\"); scanf_s(\"%d\",&y); printf(\"%d+%d=%d\\n\",x,y,x+y); printf(\"%d-%d=%d\\n\",x,y,x-y); printf(\"%d*%d=%d\\n\",x,y,x*y); printf(\"%d/%d=%d\\n\",x,y,x/y); printf(\"%d%%d=%d\\n\",x,y,x%y); return 0; } #include for(i=1;i<=100;i++){ sum=sum+i; } printf(\"sum=%d\\n\",sum); return 0; } #include printf(\"Enter m:\"); scanf(\"%d\",&m); for(i=m;i<=100;i++) s=s+i; printf(\"sum=%d\\n\",s); return 0; } #include printf(\"Enter m:\"); scanf(\"%d\",&m); printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=m;i<=n;i++) s=s+1.0/i; printf(\"sum=%f\\n\",s); return 0; } #include double s=0.0; printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=1;i<=n;i++) s=s+1.0/(2*i-1); printf(\"sum=%f\\n\",s); return 0; } #include double s=1.0,t=1.0,sign=1.0; printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=1;i printf(\"sum=%.3f\\n\",s); return 0; } #include double fahr,celsius; printf(\"Enter low:\"); scanf_s(\"%d\",&low); printf(\"Enter uper:\"); scanf_s(\"%d\",&uper); printf(\"fahr celsius\\n\"); for(fahr=low;fahr<=uper;fahr+=2){ celsius=5.0/9.0*(fahr-32.0); printf(\"%3.0f %6.1f\\n\",fahr,celsius); } return 0; } #include double p,sum=0.0; printf(\"Enter m:\"); scanf(\"%d\",&m); printf(\"Enter n:\"); scanf(\"%d\",&n); p=1.0; for(i=1;i<=m;i++) p=p*i; sum=sum+p; p=1.0; for(i=1;i<=n;i++) p=p*i; sum=sum+p; printf(\"sum=%.0f\\n\",sum); return 0; } #include printf(\"Enter x:\"); scanf(\"%d\",&x); printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=1;i<=n;i++) p=p*x; printf(\"%d的%d次方是%.0f\\n\",x, n,p); return 0; } #include printf(\"Enter n:\"); scanf(\"%d\",&n); for(i=0;i<=n;i++) printf(\"pow(3,%d)=%.0f\\n\",i,pow(3.0,i)); return 0; } #include for(i=100;i<=1000;i++){ sum+=sqrt(i); } printf(\"sum=%.2f\\n\",sum); return 0; } 实验3 #include double a, b, c, d; printf(\"Enter a, b, c: \"); scanf(\"%lf%lf%lf\",&a,&b,&c); d=b*b-4*a*c; if(a==0) if(b==0) if(c==0) printf(\"系数均为,方程无意义!\\n\"); else printf(\"a、b为,c不为,方程不成立!\\n\"); else printf(\"x=%.2f\\n\",c/b); else if(d>=0){ printf(\"x1=%.2f\\n\",(-b+sqrt(d))/(2*a)); printf(\"x1=%.2f\\n\",(-b-sqrt(d))/(2*a)); }else{ printf(\"x1=%.2f+%.2fi\\n\",-b/(2*a),sqrt(-d)/(2*a)); printf(\"x1=%.2f-%.2fi\\n\",-b/(2*a),sqrt(-d)/(2*a)); } return 0; } #include printf(\"Enter x: \"); scanf(\"%d\",&x); if(x<0) y=-1; else if(x==0) y=0; else y=1; printf(\"sign(%d)=%d\\n\",x,y); return 0; } #include int letter=0,blank=0,digit=0,other=0,i; char ch; printf(\"Input 10 characters: \"); for(i=0;i<10;i++){ ch=getchar(); if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z') letter++; else if(ch==' '||ch=='\\n') blank++; else if(ch<='9'&&ch>='0') digit++; else other++; } printf(\"letter=%d, blank=%d, digit=%d, other=%d\\n\",letter,blank,digit,other); return 0; } #include printf(\"Input Grade: \"); grade=getchar(); switch(grade){ case 'A':; case 'a':printf(\"%c对应的百分制成绩区间是~100\\n\",grade);break; case 'B':; case 'b':printf(\"%c对应的百分制成绩区间是~90\\n\",grade);break; case 'C':; case 'c':printf(\"%c对应的百分制成绩区间是~79\\n\",grade);break; case 'D':; case 'd':printf(\"%c对应的百分制成绩区间是~69\\n\",grade);break; case 'E':; case 'e':printf(\"%c对应的百分制成绩区间是~59\\n\",grade);break; default:printf(\"数据输入错误\\n\"); } return 0; } #include int choice,count; for(count=0;count<5;count++){ printf(\"[1]apple\\n\"); printf(\"[2]pear\\n\"); printf(\"[3]orange\\n\"); printf(\"[4]grape\\n\"); printf(\"[0]exit\\n\"); printf(\"Enter your choice:\"); scanf(\"%d\",&choice); switch(choice){ case 0: return 0; case 1:printf(\"price is %.2f\\n\",3.0);break; case 2:printf(\"price is %.2f\\n\",2.5);break; case 3:printf(\"price is %.2f\\n\",4.1);break; case 4:printf(\"price is %.2f\\n\",10.2);break; default:printf(\"price is %.2f\\n\",0.0); } } return 0; } #include double grade; for(i=0;i<5;i++){ printf(\"Enter grade: \"); scanf(\"%lf\",&grade); if(grade<60.0) printf(\"Fail\\n\"); else printf(\"Pass\\n\"); } return 0; } #include printf(\"Enter 3 sides of the triangle: \"); scanf(\"%lf %lf %lf\",&a,&b, &c); if(a+b>c&&a+c>b&&b+c>a){ s=(a+b+c)/2; printf(\"area=%.2f; perimeter=%.2f\\n\",sqrt(s*(s-a)*(s-b)*(s-c)),a+b+c); }else printf(\"These sides do not correspond to a valid triangle\\n\"); return 0; } #include double salary,rate; printf(\"Enter the salary: \"); scanf(\"%lf\",&salary); if(salary<=850) rate=0.0; else if(salary<=1350.0) rate=0.05; else if(salary<=2850.0) rate=0.1; else if(salary<=5850.0) rate=0.15; else rate=0.2; printf(\"tax=%.2f\\n\",rate*(salary-850)); return 0; } #include int i,n,grade,a=0,b=0,c=0,d=0,e=0; printf(\"Enter n: \"); scanf(\"%d\",&n); for(i=0;i case 10:a++;break; case 8:b++;break; case 7:c++;break; case 6:d++;break; case 5: case 4: case 3: case 2: case 1: case 0:e++;break; } } printf(\"The number of A(90~100):%d\\n\",a); printf(\"The number of B(80~89):%d\\n\",b); printf(\"The number of C(70~79):%d\\n\",c); printf(\"The number of D(60~69):%d\\n\",d); printf(\"The number of E(0~59):%d\\n\",e); return 0; } #include printf(\"输入x运算符y:\"); scanf(\"%d%c%d\",&x,&sign, &y); if(sign=='*') printf(\"%d * %d = %d\\n\",x,y,x*y); else if(sign=='/') printf(\"%d / %d = %d\\n\",x,y,x/y); else if(sign=='%') printf(\"%d Mod %d = %d\\n\",x,y,x%y); else printf(\"运算符输入错误!\\n\"); return 0; } 实验4 #include int flag,denominator; double s,eps,item; printf(\"Input eps:\"); scanf(\"%lf\",&eps); s=0.0; flag=1; denominator=1; item=1.0; while(fabs(item)>eps){ item=flag*1.0/denominator; s=s+item; flag=-flag; denominator=denominator+3; } printf(\"s=%.6f\\n\",s); return 0; } #include printf(\"Input integers:\"); scanf(\"%d\",&x); while(x>0){ if(x%2!=0) sum=sum+x; scanf(\"%d\",&x); } printf(\"The sum of the odd numbers is %d\\n\",sum); return 0; } #include printf(\"Input an integer:\"); scanf(\"%d\",&num); count=0; do{ num=num/10; count++; }while(num!=0); printf(\"count=%d\\n\",count); return 0; } #include printf(\"Input n:\"); scanf(\"%d\",&n); printf(\"Input numbers:\"); scanf(\"%d\",&x); min=x; for(i=1;i int main(){//4-1-6 int n,s=0,c=0; printf(\"Input an integer:\"); scanf(\"%d\",&n); do{ s+=n%10; n/=10; c++; }while(n); printf(\"count=%d, sum=%d\\n\",c,s); return 0; } #include double a,b,c,s=0.0; int i,n; printf(\"Input n:\"); scanf(\"%d\",&n); for(a=1.0,b=1.0,i=0;i #include #include double h,sum=0.0; printf(\"Input height: \"); scanf(\"%lf\",&h); printf(\"Input n: \"); scanf(\"%d\",&n); sum+=h; for(i=1;i<=n;i++){ sum+=h; h/=2.0; } printf(\"distance=%.1f\\n\",sum); printf(\"height=%.1f\\n\",h); return 0; } #include int m,n,i,j,st,c=0; printf(\"Input m: \"); scanf(\"%d\",&m); if(m==1) m++; printf(\"Input n: \"); scanf(\"%d\",&n); for(i=m;i<=n;i++){ st=sqrt((double)i); for(j=2;j<=st;j++) if(!(i%j)) break; if(j>st){ printf(\"%d \",i); c++; if(!(c%6)) printf(\"\\n\"); } } return 0; } #include int money,f1,f2,f5,count=0; printf(\"Input money: \"); scanf(\"%d\",&money); for(f1=1;f1<=money-7;f1++) for(f2=1;f2<=money-6;f2++) for(f5=1;f5<=money-3;f5++) if(f1+2*f2+5*f5==money) count++; printf(\"count=%d\\n\",count); for(f1=1;f1<=money-7;f1++) for(f2=1;f2<=money-6;f2++) for(f5=1;f5<=money-3;f5++) if(f1+2*f2+5*f5==money) printf(\"fen5: %d fen2: %d fen1: %d\\n\",f5,f2,f1); return 0; } #include int m,n,k,a,b,c,tmp; printf(\"Input m: \"); scanf(\"%d\",&m); printf(\"Input n: \"); scanf(\"%d\",&n); for(k=m;k<=n;k++){ tmp=k; a=tmp%10; tmp/=10; b=tmp%10; tmp/=10; c=tmp; if(a*a*a+b*b*b+c*c*c==k) printf(\"%d\(%d*%d*%d+%d*%d*%d+%d*%d*%d=%d)\\n\",k,c,c,c,b,b,b,a,a,a,k); } return 0; } #include for(i=1;i<=200;i++){ s=1; for(j=2;j<=i/2;j++) if(i%j==0) s=s+j; if(s==i){ printf(\"%d=1\",i); for(j=2;j<=i/2;j++) if(i%j==0) printf(\"+%d\",j); printf(\"\\n\"); } } return 0; } #include return 1; if(x==0) return 0; return -1; } int main(){ int x; printf(\"Enter x:\"); scanf(\"%d\",&x); printf(\"sign(%d)=%d\\n\",x,sign(x)); return 0; } #include int main(){ int x,s=0; printf(\"Input integers: \"); scanf(\"%d\",&x); while(x>0){ if(!even(x)) s+=x; scanf(\"%d\",&x); } printf(\"The sum of the odd is %d\\n\",s); return 0; } #include double distance(double x1,double y1, double x2, double y2){ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main(){ double x1, y1, x2, y2; printf(\"Input (x1, y1):\"); scanf(\"%lf%lf\",&x1,&y1); printf(\"Input (x2, y2):\"); scanf(\"%lf%lf\",&x2,&y2); printf(\"distance=%.2f\\n\",distance(x1,y1,x2, y2)); return 0; } #include int k,sqrtm=sqrt((double)m); for(k=2;k<=sqrtm;k++) if(m%k==0) return 0; return 1; } int main(){ int m,n,c=0,s=0,k; printf(\"Input m:\"); scanf(\"%d\",&m); printf(\"Input n:\"); scanf(\"%d\",&n); for(k=(m==1?2:m);k<=n;k++) if(prime(k)){ c++; s+=k; } printf(\"count=%d, sum=%d\\n\",c,s); return 0; } #include int countdigit(int number, int digit){ int c=0; if(number<0) number=-number; do{ if(number%10==digit) c++; number/=10; }while(number); return c; } int main(){ int n; printf(\"Enter an integer:\"); scanf(\"%d\",&n); printf(\"Number of digit 2: %d\\n\",countdigit(n,2)); return 0; } #include x=m%10; s+=x*x*x; m/=10; }while(m); if(s==n) return 1; return 0; } int main(){ int m,n,i; printf(\"Input m:\"); scanf(\"%d\",&m); printf(\"Input n:\"); scanf(\"%d\",&n); for(i=m;i<=n;i++) if(is(i)) printf(\"%d\\n\",i); return 0; } #include double sum=0.0;/*需要初始化为*/ for(i=1;i<=10;i++)/*上界是*/ sum=sum+fact(i); printf(\"1!+2!+...+10!=%f\\n\",sum); return 0; } double fact(int n){ int i; double result=1.0; for(i=1;i<=n;i++) result=result*i;/*result中累积n!*/ return result; } 实验7 #include int a[6][6],n,i,j,flag=1; printf(\"Input n:\"); scanf(\"%d\",&n); printf(\"Input array:\\n\"); for(i=0;i if(flag==0) break; } if(flag==0) printf(\"No\\n\"); else printf(\"Yes\\n\"); return 0; } #include int a[6][6],n,i,j,row,col; printf(\"Input n:\"); scanf(\"%d\",&n); printf(\"Input array:\\n\"); for(i=0;i for(i=0;i for(j=0;j printf(\"a[%d][%d]=%d\\n\",row,col,a[row][col]); break; } } if(i>=n)/*所有行都检测过没有找到鞍点*/ printf(\"NO\\n\"); return 0; } #include printf(\"Input a character:\"); c=getchar(); getchar(); printf(\"Input a string:\"); gets(s); i=0; while(s[i]!='\\0'){ if(s[i]==c) index=i; i++; } if(index>-1) printf(\"index=%d\\n\",index); else printf(\"Not found\\n\"); return 0; } #include int i,upcase=0,count=0; printf(\"Input a string:\"); gets(s); i=0; while(s[i]!='\\0'){ if(s[i]>='A'&&s[i]<='Z'){ upcase++; switch(s[i]){ case 'A': case 'E': case 'I': case 'O': case 'U':count++; } } i++; } if(upcase) count=upcase-count; printf(\"count=%d\\n\",count); return 0; } #include printf(\"Input a string:\"); gets(s); i=0; while(s[i]!='\\0'){ if(s[i]>='A'&&s[i]<='Z') s[i]='Z'-(s[i]-'A'); i++; } printf(\"After replaced: %s\\n\",s); return 0; } #include printf(\"Input a string:\"); gets(s); i=0; while(s[i]!='\\0'){ if(s[i]>='0'&&s[i]<='9'){ n=n*16+s[i]-'0'; i++; continue; } switch(s[i]){ case 'a': case 'A':n=n*16+10;break; case 'b': case 'B':n=n*16+11;break; case 'c': case 'C':n=n*16+12;break; case 'd': case 'D':n=n*16+13;break; case 'e': case 'E':n=n*16+14;break; case 'f': case 'F':n=n*16+15;break; } i++; } printf(\"Hex=%d\\n\",n); return 0; } 实验8 #include void move(int *, int, int); int main(){ int m, n, i, a[80], *p; printf(\"Input n, m:\"); scanf(\"%d%d\",&n, &m); for(p=a,i=0;i printf(\"After moved:\"); for(i=0;i void move(int *x,int n, int m){ int i,j,k; for(i=0;i x[j]=x[j-1];/*设置断点*/ x[0]=k; } } #include int search(int *, int, int); int main(){ int *a,n,i,x,index; printf(\"Input n:\"); scanf(\"%d\",&n); if((a=(int*)malloc(n*sizeof(int)))!=NULL) exit(1); printf(\"Input %d integers:\",n); for(i=0;i printf(\"Not found\\n\"); else printf(\"index=%d\\n\",index+1); free(a); return 0; } int search(int *a,int n,int x){ int i; for(i=0;i printf(\"Input n:\"); scanf(\"%d\",&n); if((a=(int*)malloc(n*sizeof(int)))!=NULL) exit(1); printf(\"Input %d integers:\",n); for(i=0;i int max(int *a,int n){ int i,index=0; for(i=1;i void swap(int *x,int *y){ int t=*x; *x=*y; *y=t; } void sort(int *a,int n){ int i,j; for(i=n;i>0;i--){ j=max(a,i); swap(a+i-1,a+j); } } #include int n,i,total,token,*a; printf(\"Input n:\"); scanf(\"%d\",&n); if((a=(int*)malloc(n*sizeof(int)))==NULL) exit(1); for(i=0;i token=0;/*报数的当前值*/ while(token<3){/*未出队的依次报数*/ if(a[i]!=0) token++; if(token<3)/*未满m继续报数*/ i=(i+1)%n; } a[i]=0;/*报到的出队*/ i=(i+1)%n; total--;/*队中人数减*/ } for(i=0;i #include char s[80],m[80]; int length,max=0,i; printf(\"Input 5 strings: \"); for(i=0;i<5;i++){ scanf(\"%s\",s); length=strlen(s); if(length>max){ max=length; strcpy(m,s); } } printf(\"The longest is: %s\\n\",m); return 0; } #include void delchar(char *s,char c){ int i=0; while(*s!='\\0'){ if(*s==c)/*遇到字符c*/ strcpy(s,s+1);/*将该字符后的部分拷贝成从当前位置开始的串*/ s++; } } int main(){ char s[80],c; printf(\"Input a string: \"); gets(s); printf(\"Input a char: \"); scanf(\"%c\",&c); delchar(s,c); printf(\"After deleted, the string is: %s\\n\",s); return 0; } #include void strmcpy(char *s, char *t, int m){ strcpy(s,t+m-1); } int main(){ char s[80],t[80]; int m; printf(\"Input a string: \"); gets(t); printf(\"Input a integer: \"); scanf(\"%d\",&m); strmcpy(s,t,m); printf(\"Output is: %s\\n\",s); return 0; } #include int i=0,j=strlen(s)-1; while(i return 1; } int main(){ char s[80]; printf(\"Input a string: \"); gets(s); if(is_sym(s)) printf(\"YES\\n\"); else printf(\"NO\\n\"); return 0; } #include int up=0,low=0,space=0,digit=0,other=0,i; printf(\"Input a string: \"); gets(s); for(i=0;s[i]!='\\0';i++){ if(s[i]>='A'&&s[i]<='Z'){ up++; continue; } if(s[i]>='a'&&s[i]<='z'){ low++; continue; } if(s[i]>='0'&&s[i]<='9'){ digit++; continue; } if(s[i]==' '||s[i]=='\'){ space++; continue; } other++; } printf(\"大写字母个数为:%d\\n小写字母个数为:%d\\n空格个数为:%d\\n数字个数为:%d\\n其他字符个数为:%d\\n\",up,low,space,digit,other); return 0; } 实验9 #include int hour,minit,second; }time; int n; printf(\"输入时间:\"); scanf(\"%d:%d:%d\",&time.hour,&time.minit,&time.second); printf(\"输入秒:\"); scanf(\"%d\",&n); time.second=time.second+n; time.minit+=time.second/60; time.second=time.second%60; time.hour+=time.minit/60; time.minit%=60; time.hour%=24; printf(\"新时间:%d:%d:%d\\n\",time.hour,time.minit,time.second); return 0; } #include struct student{ int num; char name[20]; double score; }stu; int n,i; double sum=0.0; printf(\"输入n:\"); scanf(\"%d\",&n); for(i=0;i printf(\"平均成绩:%.2f\\n\",sum/n); return 0; } #include struct complex{ int a,b; }x,y,z; printf(\"输入a1, a2, b1, b2:\"); scanf(\"%d%d%d%d\",&x.a,&x.b,&y.a,&y.b); z.a=x.a*y.a-x.b*y.b; z.b=x.a*y.b+x.b*y.a; printf(\"(%d+%di)×(%d+%di)=%d+%di\\n\",x.a,x.b,y.a,y.b,z.a,z.b); return 0; } #include struct book{ char name[80]; double price; }abook,min,max; int n,i; printf(\"输入n:\"); scanf(\"%d\",&n); min.price=10000; max.price=-1; for(i=0;i if(max.price #include struct addres{ char name[20]; int birthday; char phon[80]; }person[10],tmp; int n,i,j,index; printf(\"输入n:\"); scanf(\"%d\",&n); for(i=0;i scanf(\"%s%d%s\",person[i].name,&person[i].birthday,person[i].phon); } for(i=0;i person[n-i-1]=person[index]; person[index]=tmp; } for(i=0;i return 0; } #include int year,month,day; }; int day_of_year(struct date date){ int k,leap,d=date.day; int tab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; leap=(date.year%4==0&&date.year%100!=0||date.year%400==0); for(k=0;k struct date date; printf(\"输入日期:\"); scanf(\"%d%d%d\",&date.year,&date.month,&date.day); printf(\"该日期是%d年第%d天\\n\",date.year,day_of_year(date)); return 0; } #include struct time{ int hour,minit,second; }; void chang_time(struct time* t,int n){ t->second=t->second+n; t->minit+=t->second/60; t->second=t->second%60; t->hour+=t->minit/60; t->minit%=60; t->hour%=24; } int main(){ struct time t; int n; printf(\"输入时间:\"); scanf(\"%d:%d:%d\",&t.hour,&t.minit,&t.second); printf(\"输入秒:\"); scanf(\"%d\",&n); chang_time(&t,n); printf(\"新时间:%d:%d:%d\\n\",t.hour,t.minit,t.second); return 0; } 实验10 #include int s=sqrt((double)m); return s*s==m; } int same_dig(int m){ int d[3],i,j; d[0]=m%10; d[1]=(m/10)%10; d[2]=m/100; for(i=0;i<3;i++) for(j=i+1;j<3;j++) if(d[i]==d[j]) return 1; return 0; } int fun(int number){ int i,c=0; for(i=101;i<=number;i++) if(is_sqr(i)&&same_dig(i)) c++; return c; } int main(){ int number,i,count; printf(\"Enter a number: \"); scanf(\"%d\",&number); count=fun(number); printf(\"count=%d\\n\",count); return 0; } #include int k,sqrtm=sqrt((double)m); for(k=2;k<=sqrtm;k++) if(m%k==0) return 0; return 1; } int main(){ int i,n,x,count=0; printf(\"Enter n:\"); scanf(\"%d\",&n); printf(\"Enter %d numbers:\",n); for(i=0;i #include return 1.0; if(n==1) return x; return ((2*n-1)*P(n-1,x)-(n-1)*P(n-2,x))/n; } int main(){ int n; double x; printf(\"Enter n:\"); scanf(\"%d\",&n); printf(\"Enter x:\"); scanf(\"%lf\",&x); printf(\"P(%d,%.2f)=%.2f\\n\",n,x,P(n,x)); return 0; } #include