您好,欢迎访问三七文档
3-5-1正确大写字母转化成小写或者小写变大写#includestdio.hvoidmain(){charch;printf(请输入一个字符:);scanf(%c,&ch);if(ch='A'&&ch='Z'||ch='a'&&ch='z'){if(ch='A'&&ch='Z')ch=ch+32;elsech=ch-32;}elsech=ch;printf(%c\n,ch);}3-5-2大写转化成小写或者小写变大写#includestdio.hvoidmain(){charch;printf(请输入一个字符:);scanf(%c,&ch);ch=ch;{if(ch='A'&&ch='Z')ch=ch+32;elsech=ch-32;}printf(%c\n,ch);}3-5-3大写转化成小写或者小写变大写#includestdio.hvoidmain(){charch;printf(请输入一个字符:);scanf(%c,&ch);if(ch='a'&&ch='z')ch=ch-32;elseif(ch='A'&&ch='Z')ch=ch+32;elsech=ch;printf(%c\n,ch);}3-6-1正确分段函数#includestdio.hvoidmain(){intx,y;printf(请输入x:);scanf(%d,&x);if(x=1)y=x;else{if(1x10)y=2*x+1;elsey=3*x-8;}printf(x=%d,y=%d\n,x,y);}3-6-2正确分段函数#includestdio.hvoidmain(){intx,y;printf(请输入x:);scanf(%d,&x);if(x=10)y=3*x-8;elseif(x1)y=2*x+1;elsey=x;printf(x=%d,y=%d\n,x,y);}3-6-3正确#includestdio.hvoidmain(){intx,y;printf(请输入x:);scanf(%d,&x);if(x=1)y=x;elseif(1x10)y=2*x+1;elseif(x=10)y=3*x-8;printf(x=%d,y=%d\n,x,y);}计算器正确#includestdio.hvoidmain(){floatx,y,z;charch;printf(请输入操作数运算符操作数:);scanf(%f%c%f,&x,&ch,&y);switch(ch){case'+':printf(%f+%f=%f\n,x,y,x+y);break;case'-':printf(%f-%f=%f\n,x,y,x-y);break;case'*':printf(%f*%f=%f\n,x,y,x*y);break;case'/':printf(%f/%f=%f\n,x,y,x/y);break;default:printf(输入的运算符错误!\n);}}7—6正确#includestdio.hvoidmain(){intx;printf(请输入一个整数:);scanf(%d,&x);if(x%2==0)x=x;elsex=x+1;printf(%d\n,x);}实验四的补充试验题计算由键盘输入的N个数的平均值#includestdio.hvoidmain(){inti=1,n;floatx,y,s=0;printf(请输入要计算的数的个数:);scanf(%d,&n);do{scanf(%f,&x);s=s+x;i=i+1;}while(i=n);printf(%f\n,y=s/n);}4-6计算s=a+aa+aaa+aaaa+…..的值#includestdio.hvoidmain(){inta,n,i=1;longintt=0,s=0;printf(请输入a和n:);scanf(%d%d,&a,&n);while(i=n){t=t+a;s=s+t;a=a*10;i++;}printf(a+aa+aaa+...=%d\n,s);}4-5#includestdio.hvoidmain(){charc;intnum1=0,num2=0,num3=0,num4=0;printf(请输入一行字符:\n);while((c=getchar())!='\n'){if(c='a'&&c='z'||c='A'&&c='Z')num1++;elseif(c=='')num2++;elseif(c='0'&&c='9')num3++;elsenum4++;}printf(字母:%d,空格:%d,数字:%d,其他:%d\n,num1,num2,num3,num4);}4——7输出由*组成的菱形(最左边有空列)#includestdio.hvoidmain(){inti,a,b;for(i=1;i=3;i++){for(a=4-i;a0;a--)printf();for(b=2*i-1;b0;b--)printf(*);printf(\n);}for(i=1;i=2;i++){for(a=i+1;a=1;a--)printf();for(b=5-i*2;b=1;b--)printf(*);printf(\n);}}副本输出由*组成的菱形(最左边无空列)#includestdio.hvoidmain(){inti,a,b;for(i=1;i=3;i++){for(a=3-i;a0;a--)printf();for(b=2*i-1;b0;b--)printf(*);printf(\n);}for(i=1;i=2;i++){for(a=i;a=1;a--)printf();for(b=5-i*2;b=1;b--)printf(*);printf(\n);}}鸡兔同笼#includestdio.hvoidmain(){inta,b;for(a=0;a=35;a++)for(b=0;b=24;b++){if(a*2+b*4==94&&a+b==35)printf(a=%d,b=%d\n,a,b);}}水仙花数1#includestdio.hvoidmain(){intm,i,j,k,n=0;for(m=100;m=999;m++){i=m/100;j=m/10-i*10;k=m%10;if(m==i*i*i+j*j*j+k*k*k)n++,printf(%d\n,m);}printf(水仙花数的个数=%d\n,n);}水仙花数2#includestdio.hvoidmain(){inta=0,i,j,k,m,n;for(i=1;i=9;i++)for(j=0;j=9;j++)for(k=0;k=9;k++){m=i*100+j*10+k;n=i*i*i+j*j*j+k*k*k;if(m==n)a++,printf(%d\n,m);}printf(水仙花数的个数=%d\n,a);}三—7—16#includestdio.hvoidmain(){floats=100,h;intn;h=s/2;for(n=2;n=10;n++){s=s+2*h;h=h/2;}printf(第十次落地共经过的米数:%f\n,s);printf(第十次反弹的高度:%f\n,h);}#includestdio.h#includemath.hvoidmain(){inta;floatb,x,sum;a=1;b=1;x=1;sum=0;while((fabs(x))1e-7){sum=sum+x;b=b*2;x=a/b;}sum=sum*100+100;printf(%f\n,sum);}课本习题四第四大题第一小题数组的值逆序输出#includestdio.hvoidmain(){inti,a[5];for(i=0;i5;i++)scanf(%d,&a[i]);for(i=4;i=0;i--)printf(%3d,a[i]);}实验五的补充题5名学生3门课成绩求各科的平均分#includestdio.hvoidmain(){inti,j,s,v[3],score[5][3];for(i=0;i5;i++)for(j=0;j3;j++)scanf(%d,&score[i][j]);for(i=0;i3;i++){s=0;for(j=0;j5;j++)s=s+score[j][i];v[i]=s/5;}printf(各科平均成绩为:);for(i=0;i3;i++)printf(%4d,v[i]);}矩阵相加正确#includestdio.hvoidmain(){inti,j;inta[3][3],b[3][3],c[3][3];printf(请输入矩阵a[3][3]:\n);for(i=0;i3;i++)for(j=0;j3;j++)scanf(%d,&a[i][j]);printf(请输入矩阵b[3][3]:\n);for(i=0;i3;i++)for(j=0;j3;j++)scanf(%d,&b[i][j]);for(i=0;i3;i++)for(j=0;j3;j++)c[i][j]=a[i][j]+b[i][j];printf(矩阵相加结果c[3][3]:\n);for(i=0;i3;i++){for(j=0;j3;j++)printf(%d,c[i][j]);printf(\n);}}最高最低温度正确#includestdio.hvoidmain(){floatmax,min,a[31];inti;printf(请输入31天的温度:);for(i=0;i31;i++){scanf(%f,&a[i]);}min=max=a[0];for(i=0;i31;i++){if(a[i]max)max=a[i];if(a[i]min)min=a[i];}printf(最高温度:%f,最低温度:%f,max,min);}5-6计算字符串长度用指向字符串指针变量实现#includestdio.hvoidmain(){intn=0;char*c=hello,goodmoring.;while(*(c+n)!='\0')n++;printf(%d\n,n);}#includestdio.h#includestring.hvoidmain(){chara[100];inti=0;printf(inputstring\n);gets(a);while(a[i]!='\0')i++;printf(你输入的字符串的长度为%d\n,i);}#includestdio.hmain(){chara[100],*p;intn;p=a;scanf(%s,a);for(n=0;*(p+n)!='\0';n++);printf(%d\n,n);}输入一个字符串,将其逆序输出#includestdio.h#includestring.hvoidmain(){charstr[100];inti;gets(str);i=strlen(str)-1;for(;i=0;i--)putchar(str[i]);printf(\n);}判断一个字符串是否回文#includestdio.h#includestring.hvoidmain(){intx,i;charstr[100]={0};gets(str);x=strlen(str)-1;for(i=0;i=x/2;i++)///比到一半就不比了,原理已讲if(str[i]!=str[x-i])///这就是比较两端的字符break;//不是回文if(ix/2)///没执行break,就是回文printf(是回文\n);elseprintf(不是回文\n);}#includestdio.h#includestring.h#defineN50voi
本文标题:C语言课后作业答案
链接地址:https://www.777doc.com/doc-2908588 .html