资源描述:
《C语言课后作业答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、3-5-1正确大写字母转化成小写或者小写变大写#includevoidmain(){charch;printf("请输入一个字符:");scanf("%c",&ch);if(ch>='A'&&ch<='Z'
2、
3、ch>='a'&&ch<='z'){if(ch>='A'&&ch<='Z')ch=ch+32;elsech=ch-32;}elsech=ch;printf("%c",ch);}3-5-2大写转化成小写或者小写变大写#includevoidmain(){charch;printf("请输入一个字符:"
4、);scanf("%c",&ch);ch=ch;{if(ch>='A'&&ch<='Z')ch=ch+32;elsech=ch-32;}printf("%c",ch);}3-5-3大写转化成小写或者小写变大写#includevoidmain(){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",ch);}3-6-1正确分
5、段函数#includevoidmain(){intx,y;printf("请输入x:");scanf("%d",&x);if(x<=1)y=x;else{if(1voidmain(){intx,y;printf("请输入x:");scanf("%d",&x);if(x>=10)y=3*x-8;elseif(x>1)y=2*x+1;elsey=x;printf("x=
6、%d,y=%d",x,y);}3-6-3正确#includevoidmain(){intx,y;printf("请输入x:");scanf("%d",&x);if(x<=1)y=x;elseif(1=10)y=3*x-8;printf("x=%d,y=%d",x,y);}计算器正确#includevoidmain(){floatx,y,z;charch;printf("请输入操作数运算符操作数:");scanf("%f%c%f",&x,&ch,&y);sw
7、itch(ch){case'+':printf("%f+%f=%f",x,y,x+y);break;case'-':printf("%f-%f=%f",x,y,x-y);break;case'*':printf("%f*%f=%f",x,y,x*y);break;case'/':printf("%f/%f=%f",x,y,x/y);break;default:printf("输入的运算符错误!");}}7—6正确#includevoidmain(){intx;printf("请输入一个整数:");scanf
8、("%d",&x);if(x%2==0)x=x;elsex=x+1;printf("%d",x);}实验四的补充试验题计算由键盘输入的N个数的平均值#includevoidmain(){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",y=s/n);}4-6计算s=a+aa+aaa+aaaa+…..的值#includevoi
9、dmain(){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",s);}4-5#includevoidmain(){charc;intnum1=0,num2=0,num3=0,num4=0;printf("请输入一行字符:");while((c=getchar())!=''){if(c>='a'&&c<='z'
10、
11、c
12、>='A'&&c<='Z')num1++;elseif(c=='')num2++;elseif(c>='0'&&c<='9')num3++;elsen