程序设计C语言习题汇编
编写一个程序能使计算机将所输入的三个大写英文字母变成小写字母。 #include
{ char ch1,ch2,ch3;
scanf(“%c%c%c”,&ch1,&ch2,&ch3);
if (ch1>='A' && ch1<='Z') ch1=ch1+32; printf(\if (ch2>='A' && ch2<='Z') ch2=ch2+32; printf(\if (ch3>='A' && ch3<='Z') ch3=ch3+32; printf(\ }
编写一个程序实现如下功能:从键盘输入两个整数a、b,计算a2+b2的值。 #include \void main() {
int a,b;
printf(\请输入两个整数\\n\ scanf(\
printf(\两个整数平方和为:%ld\\n\}
编写一个程序实现如下功能:将整数n(0≤n≤9)转化为相应的ASCII字符,例如,整数3转换后变成字符’3’ #include \#include \void main() main() { int n; { printf(\输入整数:\\n\ int n; scanf(\ printf(\输入一位整数\\n\printf(“n=%d,对应字符为:%c\\n\ scanf(\} while (1) 下列程序的功能是:输出字符串“China”。 { #include
1
下列程序的功能是:用puts()函数输出字符串”This is a map.” #include
char str1[ ]=\ /* 字符数组str1的容量由实际字符确定 */ char str2[15]=\ /*该字符串总长度14字节,增加1字节'\\0' */ puts(str1); /* 函数调用语句,调用puts(),将str1字符串内容输出 */ puts(str2); /* 输出字符串str2的内容,都是自动换行 */ putchar('\\n'); putchar(str1[0]);putchar('\\n'); putchar(str1[1]);putchar('\\n'); putchar(str1[2]);putchar('\\n'); putchar(str1[3]);putchar('\\n'); putchar(str1[4]);putchar('\\n'); putchar(str1[5]);putchar('\\n'); putchar(str1[6]);putchar('\\n'); putchar(str1[7]);putchar('\\n'); putchar(str1[8]);putchar('\\n'); putchar(str1[9]);putchar('\\n'); putchar(str1[10]);putchar('\\n'); putchar(str1[11]);putchar('\\n'); putchar(str1[12]);putchar('\\n');
putchar(str2[13]); /* 输出字符串str1的末字符'.' */
putchar('\\n'); /* 用putchar()函数输出仅含一个转移字符的字符'\\n' */ }
下列程序的功能是:输入一个数,判断它是否既是5的倍数又是7的倍数,然后输出判断结果。
#include
int number;
printf(\
scanf(\ /* number存放被测试数据 */
if(number%5==0&&number%7==0 ) /* number是5或7的倍数 */ printf(\ else /* number不是5或7的倍数 */ printf(\}
2
下列程序的功能为:输入1个字母,如果它是小写字母,则首先将其转换成大写字母,再输出该字母的前序字母、该字母、该字母的后序字母,例如:输入g,则输出FGH;输入a,则输出ZAB;输入M,则输出LMN;输入Z,则输出YZA。 #include
{ char ch,c1,c2;
printf(\ ch=getchar();
if((ch>='a')&&(ch<='z')) /*如果是小写字母,则转换成大写字母*/ ch-=32; c1=ch-1; c2=ch+1;
if(ch=='A') c1=ch+25; else if(ch=='Z') c2=ch-25; putchar(c1); putchar(ch); putchar(c2); putchar('\\n'); }
下列程序的功能为:判断从键盘上输入的一个字符,并按下列要求输出。
若该字符是数字 输出字符串\若该字符是大写字母 输出字符串\若该字符是小写字母 输出字符串\
若该字符是其他字符 输出字符串\,@,?\
#include
scanf(\ if('0'<=c&&c<='9') printf(\
else if('A'<=c&&c<='Z') printf(\ else if('a'<=c&&c<='z') printf(\ else
printf(\,@,?\\n\}
3
程序的功能为:输入3个整数后,输出其中最大值。 #include \main() {
int a,b,c,max;
printf (\请输入3个整数:\\n\scanf (\max=a; if (c>b)
{ if (c>a) max=c;} /* c>b>a */ else /* b>c */
{if (b>a) max=b;} /* b>c>a */ printf(\个数中最大者为:%d\\n\}
下列程序的功能为:判断用户所输入的年份是否是闰年. #include
scanf(\if ( y@0==0 ) f=1;
else if (y%4==0&&y0!=0) f=1; else f=0;
if ( f ) printf(\else printf(\printf( \ a leap year\\n\}
下列程序的功能是:对输入两个整数,按从大到小顺序输出。#include
int x,y,z;
scanf(\if (x<=y)
{z=x;x=y;y=z;}
printf(\}
4