在练习之中,通过分析题目,注重解题的思路和想法。
第一题
这道题的就是一个ASCII码的转换,利用scanf语句即可。
答案
#include<stdio.h>
int main( )
{
int a;
scanf("%c",&a);
printf("d",a);
return 0;
}
第二题
这道题需要注意的就是输入为浮点数,输出为整数,利用scanf语句同样可以解决。
答案
#include <stdio.h>
int main()
{
double a;
scanf("%lf",&a);
printf("%.0f",a);
return 0;
}
第三题
这题比较简单,也是scanf语句的加强训练。
答案
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("score1=%d",a);
printf(",");
printf("score2=%d",b);
printf(",");
printf("score3=%d",c);
return 0;
}
第四题
这道题有些难度,它涉及到了大小写的转化,以及我们要知道ASCII码中字母的排序。
在ASCII码表中,小写字母和大写字母共占32个位置。
所以在代码中,我们会涉及到一个循坏语句,循坏这32个字母从中找到合适的并停止代码的运行,题目中也给出要吸收回车。
答案
#include <stdio.h>
int main()
{
int num = 0;
while ((num = getchar())!= -1)//此处的-1用来停止代码的运行
{
printf("%c\n", num+32);
getchar();
}
return 0;
}