分析下列程序运行结果
#include
main()
{
charc1,c2;
c1=97;c2=98;
printf("c1=%c,c2=%c\n",c1,c2);
printf("c1=%d,c2=%d\n",c1,c2);
}
#include
main()
{
charc1,c2;
c1=97;c2=98;
printf("c1=%c,c2=%c\n",c1,c2);
printf("c1=%d,c2=%d\n",c1,c2);
}
举一反三
- 写出下列程序的运行结果#include"stdio.h"voidmain(){charc1=’a’,c2=’b’;printf("c1=%c,c2=%c",c1,c2);printf("c1=%d,c2=%d",c1,c2);c1=c1-32;c2=c2-32;printf("c1=%c,c2=%c",c1,c2);printf("c1=%d,c2=%d",c1,c2);}
- 下列程序运行后的输出结果是【1】 void main() { char c1,c2; for(c1=’0’,c2=’9’;c1 printf(“%c%c”,c1,c2); printf(“\n”); }
- 若输入字母c,程序输出结果为; #include main() {charc1,c2; c1=getchar(); while(c1<97||c1>122)c1=getchar(); c2=c1-32; printf("%c,%c\n",c1,c2); }
- 以下程序段运行的输出结果是() #include [stdio.h][br][/br] main() { char c1,c2; c1='C'-2; c2=97; printf("%d,%c",c1,c2); } A: 65,97 B: A,97 C: A,a D: 65,a
- 下列给定程序中,函数fun的功能是进行数字字符转换。若形参ch中是数字字符'0'~'9',则将'0'转换成'9','1'转换成'8','2'转换成'7',……,'9'转换成'0';若是其他字符则保持不变;并将转换后的结果作为函数值返回。 #include 请填空(1) fun(char ch) { if (ch>='0' &&请填空(2) ) return '9'- (ch- 请填空(3) ) ; return ch ; } main() { char c1, c2; printf("\nThe result :\n"); c1='2'; c2 = fun(c1); printf("c1=%cc2=%c\n", c1, c2); c1='8'; c2 = fun(c1); printf("c1=%cc2=%c\n", c1, c2);c1='a';c2 = fun(c1); printf("c1=%cc2=%c\n", c1, c2); }