1、华南农业大学C语言上机实验答案格式:一题号一答案,相对应1001#include stdio.hint main()int a,b;scanf(%d%d,&a,&b);printf(%d,a+b);1007#include stdio.hint main()int a,b;scanf(%d%d,&a,&b);printf(%d,a+b);1014#includestdio.hvoid main()float area,r;scanf(%f,&r);area=3.14159*r*r;printf(%0.2f,area);1015#includevoid main()float f,c;scanf
2、(%f,&f);c=5.0/9*(f-32);printf(%.2f,c);1016#includemain()char a,b,c,d,e;scanf(%c%c%c%c%c,&a,&b,&c,&d,&e);if(a=A)a=a+32;if(b=A)b=b+32;if(c=A)c=c+32;if(d=A)d=d+32;if(e=A)e=e+32;printf(%c%c%c%c%c,a,b,c,d,e);1017#include stdio.hvoid main()int n,place;scanf(%ld,&n);if(n99999999)place=9;else if(n9999999)pl
3、ace=8;else if(n999999)place=7;else if(n99999)place=6;else if(n9999)place=5;else if(n999)place=4;else if(n99)place=3;else if(n9)place=2;else place=1;printf(%ldn,place);1018#includemain()int a,b,c,t;scanf(%d,%d,%d,&a,&b,&c);if(ab)t=a;a=b;b=t;if(ac)t=a;a=c;c=t;if(bc)t=b;b=c;c=t;printf(%d,%d,%d,a,b,c);1
4、019#includestdio.hmain()int a,b,c,d,e;scanf(%d%d%d%d%d,&a,&b,&c,&d,&e);if(a%27=0)printf(YESn);else printf(NOn);if(b%27=0)printf(YESn);else printf(NOn);if(c%27=0)printf(YESn);else printf(NOn);if(d%27=0)printf(YESn);else printf(NOn);if(e%27=0)printf(YESn);else printf(NOn);1020#includestdio.hmain()int
5、n;scanf(%d,&n);if(n0)printf(negativen);else printf(positiven);if(n%2=0)printf(evenn);else printf(oddn);1023#includeint main()float a,b,c;char op;scanf(%f%c%f,&a,&op,&b);switch(op)case+:c=a+b;break;case-:c=a-b;break;case*:c=a*b;break;case/:c=a/b;break;default:printf(error);break;printf(result=%.2f,c)
6、;1024#includevoid main()long i,n=1,a;scanf(%ld,&a);for(i=1;i=a;i+)n=n*i;printf(%ldn,n);1025#includevoid main()long n,sum=0,i,t=1;scanf(%ld,&n);for(i=1;i=n;i+)sum=sum+t;t=t+2;printf(%ldn,sum);1026#includevoid main()char c;int s=0,a;while(c=getchar()!=n)if(c=0&c=9)a=c-48;s=s+a;printf(%d,s);1028#includ
7、e#includemain()int m,k,i;for(m=2;m=200;m+)k=sqrt(m);for(i=2;ik)printf(%dn,m);1029#includevoid main()long r,m,n;scanf(%ld,%ld,&m,&n);while(m!=0)r=n%m;n=m;m=r;printf(%ldn,n);1030#includevoid main()char c;while(c=getchar()!=n)if(c=A&c=Z)c=c+32;putchar(c);1031#include void main()int i,num=0,word=0;char
8、c;for(i=0;(c=getchar()!=n;i+)if(c= )word=0;else if(word=0)word=1;num+;printf(%d,num);1035#includestdio.h#includemath.hvoid main()int n,i,j,k;scanf(%d,&n);for(i=1;i=2*n+1;i+)k=abs(n+1-i);for(j=1;j=k;j+)printf();for(j=1;j=2*n+1-2*k;j+)printf(*);printf(n);1037#includemain()int i,t,n;float a=2,b=1,s=0;s
9、canf(%d,&n);for(i=1;i=n;i+)s=s+a/b;t=a;a=a+b;b=t;printf(%.4fn,s);1038#include#includemain()int n,i,j,k,h;scanf(%d,&n);for(i=-n+1;i=n-1;i+)for(j=0;jabs(i);j+)printf( );for(k=1;k=1;h-)printf(%d,h);printf(n);1039#includemain()int a10;int i;for(i=0;i=0;i-)printf(%dn,ai);1040#includestdio.hmain()int a20;
10、int i,t,p=0;for(i=0;i20;i+)scanf(%d,&ai);for(t=0;ti;t+)if(at=ai)break;if(t=i)p+;printf(%d,p);1042#include#includevoid main()int m,i;scanf(%d,&m);for(i=1;i=0)break;printf(%d,i-1);1044#includestdio.hmain()int i,t,min;scanf(%d,&min);for(i=1;i10;i+)scanf(%d,&t);if(t=0;i-)an1-1-i=si-0;gets(s);n2=strlen(s
11、);for(i=n2-1;i=0;i-)bn2-1-i=si-0;if(n1n2)max=n1;else max=n2;for(i=0;i0)printf(%d,cmax);for(i=max-1;i=0;i-)printf(%d,ci);1047#includemain()int a10;int i,j,t;for(i=0;i10;i+)scanf(%d,&ai);for(i=0;i9;i+)for(j=0;jaj+1)t=aj;aj=aj+1;aj+1=t;for(i=0;i10;i+)printf(%d,ai);1050#includestdio.hmain()int i,j;char
12、a80,b80;gets(a);gets(b);for(i=0;ai!=0;i+)for(j=0;bj!=0;j+)if(ai+j!=bj)break;if(bj=0)break;if(ai!=0)printf(%d,i+1);else printf(Not Found);1051#includemain()int i,j,k,a34,max,maxj,flag;for(i=0;i3;i+)for(j=0;j4;j+)scanf(%d,&aij);for(i=0;i3;i+)max=ai0;maxj=0;for(j=0;jmax)max=aij;maxj=j;flag=1;for(k=0;ka
13、kmaxj)flag=0;break;if(flag)printf(%d,max);break;if(!flag)printf(NO);1059#includestdio.hint f(int m,int n)int r;while(r=m%n)!=0)m=n;n=r;return n;main()int a,b,n;scanf(%d%d,&a,&b);printf(%dn,f(a,b);1062#includevoid main()int a34,b43,i,j;for(i=0;i3;i+)for(j=0;j4;j+)scanf(%d,&aij);bji=aij;for(i=0;i4;i+)
14、for(j=0;j3;j+)printf(%d,bij);printf(n);1065#includestdio.hmain()printf(19n);printf(2016n);printf(2000n);printf(2016n);printf(2004n);printf(2016n);printf(2036n);printf(2020n);printf(21);1083long fanc(int a)long i,n=1;for(i=1;i1)fun(i/2);printf(%d,i%2);main()int n;scanf(%d,&n);fun(n);1091#includestdio
15、.hvoid swap(int*p1,int*p2)int temp;temp=*p1;*p1=*p2;*p2=temp;int main()int a,b;int*pa,*pb;scanf(%d%d,&a,&b);pa=&a;pb=&b;if(ab)swap(pa,pb);printf(%d%dn,a,b);1092#includestdio.h#includestring.hint f(char*p)return strlen(p);int main()char s80;int i;scanf(%s,s);i=f(s);printf(%d,i);1117#includestdio.hvoi
16、d main()int a,b;/*定义整型变量a和b*/int i,j;/*定义实型变量i和j*/a=5;b=6;i=3.14;j=i*a*b;printf(a=%d,b=%d,i=%f,j=%fn,a,b,i,j);1118#include stdio.hvoid main() float a;int b, c;char d, e;a=3.5;b=a;c=330;d=c;e=;printf(%f,%d,%d,%c,%c, a,b,c,d,e); 1119#includestdio.hvoid main()int a,b,c;float d=15,e,f;a=35%7;b=15/10;c=b
17、+;e=15/10;f=d/10;printf(%d,%d,%d,%f,%f,%f,a,b,c,d,e,f);1120#includestdio.h#includemath.hvoid main()float a,b;scanf(%f,%f,&a,&b);if(fabs(a*a+b*b-1)1e-3)printf(Yn);else printf(Nn);1121#includestring.hvoid main()char s80;/*定义字符数组s*/strcpy(s,abcdefghijklmn);printf(%s,s);1122#includestdio.h#includestring
18、.hmain()char s100=;char a30;gets(a);strcat(s,a);gets(a);strcat(s,a);gets(a);strcat(s,a);/*可以写多行代码*/printf(%s,s);1123#includestdio.hvoid main()char s50;printf(Whats your name?);gets(s);/*由键盘读入字符串*/printf(Your name is,);printf(%s,s);/*打印字符串*/1124int f1(int x)static int z=3,y=0;y+;z+;return(x+y+z);main
19、()int a=1,k;for(k=0;k3;k+)printf(%4d,f1(a);1125/*定义结构体类型*/struct studentchar name20;char sex;int num;float score;main()struct student stu;scanf(%s,stu.name);scanf(%*c%c,&stu.sex);scanf(%d,&stu.num);scanf(%f,&stu.score);printf(%sn,stu.name);printf(%cn,stu.sex);printf(%dn,stu.num);printf(%fn,stu.score
20、);1126#include stdio.hvoid main() char ch;ch = getchar();putchar(ch);1127#include stdio.hvoid main()int a,b;scanf(%d%*c%d,&a,&b);printf(%d, a+b);1145/* 判断一个数是否是回文数;*/#includeint main(void) int val; int m,sum=0; printf(请输入数字:); scanf(%d,&val); m=val; while(m) sum=sum*10+m%10; m/=10; if(val=sum) printf(Yn); else printf(Nn); return 0;6567#include stdio.hmain()printf(The first C Programn);6568#include main()printf(C:ABC.TXT);11126#include int max(int x,int y)if(xy)return x;else return y;int main()int a,b;scanf(%d%d,&a,&b);printf(%dn,max(a,b);结束!资源提供出处
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1