C语言程序设计由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“c语言程序设计答案”。
1.Problem A: Hello world!Description Xiao_ming有两个哥哥,大哥叫Da_min,二哥叫Er_min。三兄弟放学回家,父母分别跟他们打招呼。
Input 无
Output 请输出: Hello Da_min, Hello Er_min, Hello Xiao_ming!
Sample Input Sample Output Hello Da_min, Hello Er_min, Hello Xiao_ming!
HINT 请注意换行符
Append Code #include int main(){
printf(“Hello Da_min,n”);
printf(“Hello Er_min,n”);
printf(“Hello Xiao_ming!n”);} 2.Problem B: 求圆的面积和周长 Description 从键盘输入圆的半径,求圆的面积和周长,圆周率取3.14。
Input 输入一个浮点型数据,有效数字不会超过十进制的6位。
Output 输出为两行。
第一行为圆的面积,第二行为圆的周长,格式见sample。
Sample Input 3
Sample Output Area: 28.260000 Perimeter: 18.840000
HINT 了解浮点类型的输入、输出和算术运算符
Append Code 法一
#include int main(){ double r,p,s;scanf(“%lf”,&r);p=2*3.14*r;s=3.14*r*r;printf(“Area: %lfn”,s);printf(“Perimeter: %lfn”,p);} 法二
#include #define pi 3.14 int main(){
double r;
scanf(“%d”,&r);
printf(“Area: %lfn”,pi*r*r);
printf(“Perimeter: %lfn”,2*pi*r);
}
3.Problem C: 平均值 Description 求3个数的平均值。
Input 输入只有一行,为3个较小的整数。
Output 输出为这3个整数的平均值,保留3位小数。
Sample Input 1 2 3 Sample Output 2.000
HINT 注意除法运算对整型数据和浮点型数据是不一样的。
Append Code #include int main(){ int a,b,c;scanf(“%d%d%d”,&a,&b,&c);printf(“%.3lf”,(a+b+c)/3.0);}
4.Problem D: 求字符的值 Description 从键盘输入3个字符(不含双字节字符),分别输出每个字符的十进制值(ASCII码)、八进制值和十六进制值。
Input 输入为3个字符。
Output 输出为3行。
每一行为每个字符(对应输入顺序)的十进制、八进制和十六进制值,用空格分隔开。每个输出的值占3个字符,不足3个字符前面补0。
Sample Input 0 A
Sample Output 048 060 030 032 040 020 065 101 041
HINT 了解字符值的存储和整型的关系。
Append Code #include int main(){ char a,b,c;scanf(“%c%c%c”,&a,&b,&c);printf(“%.3d %.3o %.3xn”,a,a,a);printf(“%.3d %.3o %.3xn”,b,b,b);printf(“%.3d %.3o %.3xn”,c,c,c);}
5.Problem A: 最简单的程序 Description 输出一行“Hello world!”。
Input 无
Output Hello world!
Sample Input Sample Output Hello world!
HINT Append Code #include int main(){
printf(“Hello world!”);}
6.Problem B: 算术基本运算 Description 计算两整数x和y(0
Input 输入只有一行,格式见sample。
Output 输出为多行,按顺序每行输出x,y的和、差、积、商、余数、x的平方和y的三次方,格式见sample
Sample Input x = 11, y = 3
Sample Output x + y : 14 xy : %dn“,x-y);
printf(”x * y : %dn“,x*y);
printf(”x / y quotient: %d, remainder: %dn“,x/y,x%y);
printf(”x ^ 2 : %dn“,x*x);
printf(”y ^ 3 : %dn“,y*y*y);} 7.Problem C: 自增自减运算 Description C语言中有自增运算++、自减运算--,并且可以前置和后置。
编写一个程序:对输入的一个整数a,输出a++、a--、++a、--a的值。
Input 一个整数a,a是很小的整数。
Output 输出为5行,第一行为a的值,后面依次为--a、a--、a++、++a的值。
5行输出纵向a要对齐,“:”对齐,“:”前后各一个空格,后面的数值不用对齐。每行行尾都有回车。
Sample Input 0
Sample Output a : 0--a :-1 a--: 0 a++ : 0 ++a : 1
HINT Append Code #include int main(){ int a,x;scanf(”%dn“,&x);a=x;printf(” a
: %dn“,a);printf(”--a
: %dn“,--a);a=x;printf(” a--: %dn“,a--);a=x;printf(” a++ : %dn“,a++);a=x;printf(”++a
: %dn“,++a);}
8.Problem F: 绝对值 Description 求整型数据和浮点型数据的绝对值。
Input 输入两个数,第一个是整数,第二个是浮点数。
Output 输出为两行,第一行为整数的绝对值,第二行为浮点数的绝对值,注意浮点数的绝对值不输出无意义的0。
Sample Input-1 1
Sample Output 1 1
HINT 求绝对值可以用标准库函数来完成,也可以自己判断。注意浮点数的输出格式。求绝对值的函数在哪个头文件?貌似很多人会搞错,包括很多编书的人!
Append Code #include //#include int main(){
int n;
float m;
scanf(”%d%f“,&n,&m);
//n=abs(n);
//m=fabs(m);
if(n
{
n=-n;
}
if(m
{
m=-m;
}
printf(”%dn“,n);
printf(”%g“,m);
return 0;}
9.Problem A: 奇数还是偶数? Description 输入一个整数,判读它是奇数还是偶数。
Input 输入只有一行,为一个100以内的正整数。
Output 输出为一行。
若输入为偶数则输出“even”,奇数输出“odd”。Sample Input 30
Sample Output even
HINT 用整数运算可以解决,练习“?:”表达式。
Append Code #include int main(){
int n;
scanf(”%d“,&n);
if(n>=0&&n
if(n%2==0)printf(”evenn“);
else printf(”oddn“);
}
return 0;}
10.Problem B: 简单的打折计算 Description 商店规定:消费满n元,可以打八八折。设某件商品标价m元,输入购买的件数x,计算出需要支付的金额(单位:元),精确到分。
Input 输入只有一行,三个整数m、n和x,且0
Sample Input 95 300 4
Sample Output 334.40
HINT 了解浮点型的输出控制,注意整型和浮点型混合运算过程中的数据类型转换。
Append Code #include int main(){
int m,x,n,a;
float b;
scanf(”%d%d%d“,&m,&n,&x);
0
x
m
a=m*x;
if(a>n)
b=0.88*a;
else
b=a;
printf(”%.2fn“,b);
}
11.Problem C: 判断闰年 Description 输入一个正整数的年份,判断是否为闰年。
Input 输入只有一行,为一个10000以内的正整数。
Output 输出为一行。
若输入为闰年偶数则输出“Yes”,否则输出“No”。
Sample Input 2010
Sample Output No
HINT 了解逻辑运算符和关系运算符。
Append Code #include int main(){
int x;
scanf(”%d“,&x);
if(x>0&&x
{
if(x%4==0&&x%100!=0)
printf(”Yesn“);
else if(x%400==0)
printf(”Yesn“);
else
printf(”Non“);
}
else
printf(”error“);}
12.Problem D: 水仙花数 Description 如果一个三位十进制数等于其各位数字的立方和,则称这个数为水仙花数。如:13+53+33=153。
Input 一个整数x,100
Output x是水仙花数,则输出“YES”,否则为“NO”。
Sample Input 153
Sample Output YES
HINT Append Code #include int main(){
int a,b,c,x;
scanf(”%d“,&x);
a=x/100;
b=x/10%10;
c=x%10;
if(x==a*a*a+b*b*b+c*c*c)
printf(”Yes“);
else
printf(”No“);}
13.Problem E: 三个数比较大小 Description 从键盘上输入0~100之间的三个数,按从小到大的顺序输出。
Input 输入只有一行,为三个整数。
Output 按从小到大输出这三个数。
Sample Input 15 10 20
Sample Output 10 15 20
HINT 用if语句判断各种情况可以解决这个问题。
Append Code #include int main(){
int a,b,c;
scanf(”%d%d%d“,&a,&b,&c);
if(a>=b)
{
if(b>=c)
printf(”%d %d %dn“,c,b,a);
else if(c>=a)
printf(”%d %d %dn“,b,a,c);
else
printf(”%d %d %dn“,b,c,a);
}
else
{
if(a>=c)
printf(”%d %d %dn“,c,a,b);
else if(b>=c)
printf(”%d %d %dn“,a,c,b);
else
printf(”%d %d %dn“,a,b,c);
} }
14.Problem F: 奇怪的求和之一 Description 给定3个正整数a、b和c,按照如下规则求和: 如果这个数字是偶数,则累加到和中;
如果这个数字是奇数,则将大于该数的最小偶数累加到和中。
Input 三个正整数,均在100以内。
Output 一个和。
Sample Input 2 3 5
Sample Output 12
HINT 如果不会使用分支语句,可使用条件运算符判断到底将哪个数累积到和中。
Append Code #include int main(){
int a,b,c;
scanf(”%d%d%d“,&a,&b,&c);
if(a%2!=0)a++;
if(b%2!=0)b++;
if(c%2!=0)c++;
printf(”%dn“,a+b+c);
}
15.Problem G: 你过线了吗? Description 经过四年的学习,你决定报考我国著名的“285”高校之一的北青大学,经过认真的复习,残酷的考试,终于知晓了自己的考试成绩,也知道了北青大学的录取分数线,请你编程判断,自己过线了吗? Input 输入有2行,第一行有4个正整数,分别表示三门课程的分数线以及总分分数线。第二行有3个非负整数,分别表示你考的三门课程的成绩。
Output 如果你的三门课程成绩都不低于相应课程的分数线,且你的考试总分也不低于北青大学的总分分数线要求,则输出“congratulations”,否则输出“sorry”。
Sample Input 70 80 70 240 80 80 82
Sample Output congratulations
HINT 如果你不会使用分支语句,同样可以使用条件运算符实现该程序。
Append Code #include int main(){
int a,b,c,d,e,f,g,h;
scanf(”%d %d %d %dn%d %d %d“,&a,&b,&c,&d,&e,&f,&g);
h=e+f+g;
if(e>=a&&f>=b&&g>=c&&h>=d)
printf(”congratulations“);
else
printf(”sorry“);} 16.Problem I: A+B Problem(II): Input/Output
Practice Description 计算a+b,0
Input 输入的第一行是一个整数N,后面有N对整数a和b,每对a和b占一行,a,b用空格分开。
Output 每行输出一个a+b的和,顺序与输入对应。
Sample Input 2 1 2 10 20
Sample Output 3 30
HINT N给出了测试样例数,用for循环处理方便。
Append Code #include int main(){
int n,a,b,i;Scanf(“%d”,&n);For(i=0;i
17.Problem H: A+B Problem Description 计算a+b,0 Input 输入有多对整数a和b组成,每对a和b占一行,a,b用空格分开。 Output 每行输出一个a+b的值,顺序与输入对应。 Sample Input 1 2 10 20 Sample Output 3 30 HINT OJ系统上测试输入结束符为EOF(End Of File),其值为-1。用scanf()把文件所有内容读完后,会读到EOF,所以可以用来判断输入是否完成,测试时可以用Ctrl+Z产生EOF。本题解法参看FAQ。Append Code #include int main(){ int a,b; while(scanf(”%d%d“,&a,&b)!=EOF){ printf(”%dn“,a+b); } return 0;} 18.Problem A: 判断是否是元音字母 Description 输入一个英文字母,判断是否是元音字母。元音字母是:a,e,i,o u,A,E,I,O,U Input 输入一个英文字母 Output 是元音字母,输出“yes”,否则输出“no”,行尾没有回车。 Sample Input A Sample Output yes HINT Append Code #include void main(){ char ch; scanf(”%c“,&ch); if(ch>='A'&&ch ch=ch+32; if(ch=='a') printf(”yes“); else if(ch=='e') printf(”yes“); else if(ch=='i') printf(”yes“); else if(ch=='o') printf(”yes“); else if(ch=='u') printf(”yes“); else printf(”no“); } 19.Problem B: 按顺序输出三个数 Description 对于输入的3个整数,按照从小到大的顺序输出。 Input 输入3个int类型内的整数,两两之间用一个空格隔开。 Output 按照从小到大的顺序输出上述三个数,两两之间用一个空格隔开。 Sample Input 2 1 3 Sample Output 1 2 3 HINT Append Code #include void main(){ int a,b,c,temp; scanf(”%d%d%d“,&a,&b,&c); if(a { temp=a; a=b; b=temp; } if(a { temp=a; a=c; c=temp; } if(b { temp=b; b=c; c=temp; } printf(”%d %d %dn“,c,b,a);} 20.Problem E: Description 判断输入整数的奇偶性。 判断奇偶数 Input 输入为一个整数。 Output 输出只有一行,代表判断结果。如果输入的整数n是一个偶数,输出: n is an even number.否则输出: n is an odd number.见样例。 Sample Input 12 Sample Output 12 is an even number.HINT Append Code #include int main(){ int a; scanf(”%d“,&a); if(a%2==0) printf(”%d is an even number.“,a); else printf(”%d is an odd number.“,a);} 21.Problem A: 判断两个整数的大小关系 Description 输入2个整数a和b,如果a>b,则输出1,否则输出0。 Input 两个整数a和b,均不超过int类型的表示范围。 Output 表示a>b的结果:如果a>b,则输出1,否则输出0。 Sample Input 3 4 Sample Output 0 HINT Append Code #include int main(){ int a,b;scanf(”%d %d“,&a,&b);if(a>b) printf(”1“); else printf(”0“);return 0;} 22.Problem D: 成绩的等级 Description 把百分制的考试成绩转换成五级制的成绩: 90~100:Excellent 80~89:Good 70~79:Average 60~69:Pa 0~59:Failing 不在0~100之间的输入是非法数据,输出“Error”。 Input 输入多行,每行一个整数。 Output 输入所对应的成绩等级。 Sample Input-1 81 92 35 68 72 100 Sample Output Error Good Excellent Failing Pa Average Excellent HINT 用switch语句解决这个问题比较方便。 Append Code #include int main(){ int score; while(scanf(”%d“,&score)!=EOF) { if(score100) printf(”Errorn“); else { switch(score/10) { case 0: case 1: case 2: case 3: case 4: case 5:printf(”Failingn“);break; case 6:printf(”Pan“);break; case 7:printf(”Averagen“);break; case 8:printf(”Goodn“);break; case 9: case 10:printf(”Excellentn“);break; } } } return 0;} 23.Problem E: 输出是m的倍数或n的倍数、但不是 m和n的公倍数的数 Description 输出1~k之间是m的倍数或n的倍数、但不是m和n的公倍数的数,其中1 Input 输入三个整数,依次为k、m、n。 Output 从小到大输出符合题意的所有整数,两数之间用一个空格分开。 Sample Input 15 2 3 Sample Output 2 3 4 8 9 10 14 15 HINT 难点在于输出格式的控制:空格在数的中间,学会用循环时边界情况的特殊处理。 Append Code #include int main(){ int k,m,n,a,i=1;scanf(”%d %d %d“,&k,&m,&n);if(m a=m;else a=n;printf(”%d“,a);for(i=a+1;i } if((i%m==0&&i%n!=0)||(i%n==0&&i%m!=0)) printf(” %d“,i);} return 0; 24.Problem B: 两整数相加减 Description 计算a+b和a-b。 Input 输入为一对整数a和b。a,b用空格分开。 Output 输出a+b和a-b的计算结果,各占一行。 Sample Input 1 2 Sample Output 3-1 HINT Append Code #include int main(){ int a,b;scanf(”%d %d“,&a,&b); printf(”%dn“,a+b); printf(”%dn“,a-b);} 25 Problem C: 它满足条件吗? Description 需要判断给定的一个整数是否同时满足如下三个条件: 1.它是一个完全平方数。2.它是一个偶数。3.它是一个正数。 注:若一个数能表示成某个自然数的平方的形式,则称这个数为完全平方数。例如: 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529 Input 一个int范围内的整数。 Output 如果输入的数字满足条件,则输出yes,否则输出no。 Sample Input 100 Sample Output yes HINT 注意逻辑表达式判断三个条件的顺序。如果你不会使用分支语句,同样可以使用条件运算符实现该程序。 库函数sqrt()可以用于求一个数的平方根。 Append Code #include #include int main(){ int a;scanf(”%d“,&a); if(a==sqrt(a)*sqrt(a)&&a%2==0&&a>0) printf(”yes“); else printf(”no“);} 26.Problem F: 多路分支 Description 编写一个完整的程序,运行时向用户提问”你考试考了多少分?(0-100)“接受输入后判断其等级并显示出来等级: 优:90 Input 输入任意一个整数分数值,显示等级;再输入任意一个整数分数值,显示等级;....直到测试数据较充分,可输入-1止。 Output 对任意输入的分数值,输出对应的等级,直到输入的数为-1时才退出运行.Sample Input 102 100 90 80 70 60 50 0-80-1 Sample Output grad must between 0 and 100 优 优 良 中 中 差 差 grad must between 0 and 100 grad must between 0 and 100 HINT Append Code #include int main(){ int x; while(scanf(”%d“,&x)!=EOF) { if(x100) printf(”grad must between 0 and 100n“); else if(x>=90) printf(”优n“); else if(x>=80) printf(”良n“); else if(x>=60) printf(”中n“); else if(x>=0) printf(”差n“); } return 0;} Problem D: 有多少人? Description 学校举行运动会,如果全体学生按照3人一队列队,则多了1个人;如果按照4人一队列队,则多了2个人;如果按照5人一队排队,则多了3个人。请问这个学校有多少学生? Input 一个int类型的正整数N,是学生人数的上界,即:该校学生数不超过N。 Output 所有可能的学生数,每个数占一行。 Sample Input 200 Sample Output 58 118 178 HINT Append Code #include #include int main(){ int n,i; scanf(”%d“,&n); for(i==1;i printf(”%dn“,i);} return 0;} Problem C: 正负数各有几个? Description 输入若干个整数,求其中正数、负数的个数。 Input 输入分为2行:第一行是一个数字N>0,表示下面有N个整数。第2行是N个整数,都是int类型的。 Output 输出所输入的N个整数的正数个数和负数个数,并用空格分开2个输出。Sample Input 10 2 3 4 5-1-2-3-4-5 Sample Output 5 5 HINT 貌似还有一种叫做0的数。 Append Code #include int main(){ int n,a,i,num1=0,num2=0; scanf(”%d“,&n);for(i=0;i { scanf(”%d“,&a); if(a>0) num1++; else if(a num2++; } printf(”%d %dn“,num1,num2); return 0;} Problem A: A+B Problem(III): Input/Output Practice Description 计算a+b,0 Input 输入有多对整数a和b组成,每对a和b占一行,a,b用空格分开。当测试样为0 0时表示输入结束,0 0不参与运算。 Output 每行输出一个a+b的值,顺序与输入对应。 Sample Input 1 2 10 20 0 0 Sample Output 3 30 HINT 练习break的使用。 Append Code #include int main(){ int a,b;while(scanf(”%d %d“,&a,&b)!=EOF) { if(a!=0||b!=0) } printf(”%dn“,a+b); else break; return 0;} 30 Problem B: A+B Problem(IV): Input/Output Practice Description 计算a+b,0 Input 输入有多对整数a和b组成,每对a和b占一行,a,b用空格分开。 Output 每行输出一个a+b的值,顺序与输入对应。每个格式样例之间用一个空行分隔开。 Sample Input 1 2 10 20 15 35 Sample Output 3 30 50 HINT 由于输出的和比空行多一个,所以全部计算放在一个循环里是不行的,必须要特殊处理开头或者结尾。 Append Code #include int main(){ int a,b,n=0;while(scanf(”%d %d“,&a,&b)!=EOF){ n++; if(n==1) printf(”%dn“,a+b); else printf(”n%dn“,a+b); } return 0;} Problem C: n个数的最大值和最小值 Description 找出n个数中最大的数和最小的数,并将它们的值输出出来。 Input 输入为n+1个整数,都在int类型范围内。这些数可能用若干空格或者换行符分隔开。输入的第1个数为n,表示后续有n个数输入。从输入的第2个数开始,求出直到第n+1个数中最大的数和最小的数。 Output 输出为两行,格式见sample。 Sample Input 3 0 1-1 Sample Output The maximum number is 1.The minimum number is-1.HINT 分隔符是空格还是回车都是空白符,对scanf(”%d“)来说没有区别;先读入n,然后用for循环就很容易控制读入n个数的过程。 Append Code #include int main(){ int n,i,max,min; scanf(”%d“,&n); int a[n]; for(i=0;i scanf(”%d“,&a[i]); max=a[0]; min=a[0]; for(i=0;i { if(max max=a[i]; if(min>a[i]) min=a[i]; } printf(”The maximum number is %d.n“,max); printf(”The minimum number is %d.“,min); return 0;} 32.Problem D: 求100以内的素数 Description 素数是只能被1和自身整除的正整数,根据数学定义1不是素数。素数也叫质数。 Input 输入为两个整数m和n,满足0 Output 从大到小输出m~n之间的所有素数,一个素数一行。如果m~n之间没有素数,则不输出任何数。 输出的所有数在两行“=====”之间。 Sample Input 2 12 Sample Output ===== 11 7 5 3 2 ===== HINT 利用素数的数学规律可以很容易的解出此题,题目给出的数据范围是关键。 Append Code #include #include int main(){ int m,n,i,j,k,t;scanf(”%d %d“,&m,&n);printf(”=====n“);for(i=n;i>=m;i--){ t=0; for(j=2;j if(i%j==0) t=1; if(t==0&&i>1) printf(”%dn“,i);} printf(”=====“);return 0;} 33.Problem E: 是否构成三角形? Description 给出三个整数,代表三条边的长度,判断这三条边的长度是否能构成一个三角形? Input 第一行是n(1 接下来有n行,每一行包含三个整数,表示三个边长(1 Output 如果三条边能构成三角形,输出YES,否则输出NO Sample Input 3 1 2 3 2 8 7 20 20 1 Sample Output NO YES YES HINT Append Code #include int main(){ int a,b,c,n,i;scanf(”%d“,&n);for(i=0;i {scanf(”%d%d%d“,&a,&b,&c); if(a+b>c&&a+c>b&&b+c>a) printf(”YESn“);else printf(”NOn“);} return 0;} 34.Problem C: 简单的整数排序 Description 对给出的若干整数按从小到大排序。 Input 输入的第一个数为n(n Output 按从小到大的顺序输出这些整数,每两个整数之间用一个空格分隔开,最后一个整数后面没有空格。 Sample Input 10 3 9 1 5 2 8 5 6 7 3 Sample Output 1 2 3 3 5 5 6 7 8 9 HINT 排序前必须把所有的整数都存储下来。因为只有最多1000个数,1秒的时间足够任何排序算法运行处结果来。 Append Code #include int main(){ int c,i,n,j; int a[1000]; scanf(”%d“,&n); for(i=0;i scanf(”%d“,&a[i]); for(i=1;i { for(j=0;j { if(a[j]>a[j+1]) { c=a[j]; a[j]=a[j+1]; a[j+1]=c; } } } printf(”%d“,a[0]); for(i=1;i printf(” %d“,a[i]); return 0;} 35.Problem A: Description 购物的路程 Saya和Kudo一起去购物。假定她们逛的街是一条直线,而商铺是这条直线上的一些点。她们将车停在该直线最左端的店铺处,然后从左向右开始逛每一个店铺,然后从最右边的店铺再返回到停车处。你的任务是计算她们走了多少路。 Input 输入有多组。每一组的第一行是N(0 Output 对每组输入,输出她们走的路长。 Sample Input 4 13 89 37 6 7 30 41 14 39 42 0 Sample Output 152 70 HINT Append Code #include int main(){ int n,i,max,min,a[100001]; while(scanf(”%d“,&n)&&n!=0) { scanf(”%d“,&a[0]); min=max=a[0]; for(i=1;i { scanf(”%d“,&a[i]); if(a[i]>max) max=a[i]; if(a[i] min=a[i]; } printf(”%dn“,(max-min)*2); } return 0;} 36.Problem B: 求累加和 Description 编程求min~max的累加和(含min和max),其中max>=min>0。部分程序已经给出,请填充其中的空白语句,并提交填充后的完整程序。 Input 输入为多行。第一行是一个整数N>0,表示后面有N个测试用例。后面有N行,每行包含2个整数,分别是min和max。 Output 输出为N行,每个测试用例的计算结果占据一行。每行的格式为: case i:sum=s.其中i表示测试用例的编号(从1开始),s是该测试用例对应的累加和(设不超过int的表示范围)。 Sample Input 3 1 10 1 100 1 1 Sample Output case 1:sum=55.case 2:sum=5050.case 3:sum=1.HINT Append Code #include int main(){ int n,i,j,max,min,sum; scanf(”%d“,&n); for(i=0;i { sum=0; scanf(”%d%d“,&min,&max); if(max==min) printf(”case %d:sum=%d.n“,i+1,min); else { for(j=min;j sum=sum+j; printf(”case %d:sum=%d.n“,i+1,sum); } } return 0;} 37.Problem G: 顺序输出字母 Description 按字母顺序输出两个字母st和ed之间的所有字母,但不包括st和ed。不输出逆序。 Input 两个字母st和ed,都是大写字母,用一个空格分开。 Output 在一行内按顺序输出st和ed之间的所有字母,但不包括st和ed。例如: 输入为A和E,则输出为BCD; 输入为A和B,则什么字母也不输出,只有一个空行; 输入为E和A,也是什么字母也不输出,只有一个空行。最后要输出一行(行尾不回车): ***END*** Sample Input A C Sample Output B ***END*** HINT Append Code #include int main(){ char st,ed,a; int i; scanf(”%c%c%c“,&st,&a,&ed); { for(i=st+1;i printf(”%c“,i); printf(”n***END***“); } return 0;} 38.Problem F: 单字母变换 Description Tom和Jack是密码学爱好者,他们在聊天时经常使用一些暗语。他们使用的一种最简单的暗语是:将要说的每句话里面的英文字母变成这个字母之后的某个字母。现在要求你写一个程序,将一个字母变成它之后的某个字母。 Input 输入有2个:一个大写字母c和一个正整数d(0 Output 输出字母c之后的第d个字母。大小写与c一致。如果c之后的某个字母已经超出'Z',则再从字母'A'开始计数。 如:c='A',d=3,则输出应为:D。若:c='Y',d=3,则输出应为:B。 Sample Input A 3 Sample Output D HINT Append Code #include int main(){ char c; int d; scanf(”%c%d“,&c,&d); if(c+d printf(”%c“,c+d); else printf(”%c“,c+d-26); return 0;} 39.Problem B: 登录密码验证 Description 编写一个程序,模拟用户登录系统的密码验证过程。系统提供给用户的密码长度最长为20个字符,若密码输入错误可以再次输入。但为了保证用户密码安全,若连续输入密码错误超过5次就会锁定账号一段时间。 Input 输入为若干个串,至EOF结束。输入的第一个串是用户的正确密码,后面的串为模拟用户登录时的输入的密码。 Output 每次输入错误的密码,输出一个“Wrong!”,若输入的密码为正确的,输出一个“Welcome!”,并结束密码测试。若前5次输入的密码都是错误的,则后面的输入中不管是否有正确的密码都输出“Out of limited!”。 Sample Input abcdefg 123456 kkkkkkkk abcdefg Sample Output Wrong!Wrong!Welcome! HINT 输入可以用scanf(”%s“)处理,密码比较用字符串的比较可以完成。 Append Code #include #include int main(){ char a[20],b[20]; int i,j=1; scanf(”%s“,a); while(scanf(”%s“,b)!=EOF) { if(j { if((strcmp(a,b)==0)) { printf(”Welcome!n“); break; } else printf(”Wrong!n“); j++; } else printf(”Out of limited!n"); } } 40.Problem C: 兔子的繁殖问题 Description 假设一对兔子每月能生一对小兔(一雌一雄),每对小兔出生后的下一个月是没有繁殖能力的,至出生后的第三个月开始又可以每月生一队小兔,问从一对刚出生的小兔开始,经过若干个月后一共有多少兔子(假设在此过程中兔子没有死亡)? 这个问题是意大利数学家菲波那契(Fibonacci)在他1202年出版的《算盘全书》中提出来的,从第一对刚出生的小兔开始每月的兔子数被乘坐菲波那契序列。 Input 输入的第一个数为n,接下来有n个数字。每个数字为一个月份m(m Output 输出为n行,每行为第m个月后的兔子总数。 1032]《C语言程序设计》选择题 [单选题]12.关于C语言程序描述正确的是()A:每个函数必须要有return语句 B:主函数必须位于程序的开头 C:程序中每行只能写一条语句 D:一个程序中只...... 《C 语言程序设计》主要在计算机软件、计算机网络、计算机应用、通信技术、智能电子、电子信息工程、多媒体以及核工程与核技术等专业中开设,是电子信息类、机械类等工科专业...... 信息工程学院学生会科技部关于举办信息工程学院C语言程序设计大赛的策划书一、活动背景:随着计算机技术的快速发展,计算机程序语言的多样化,C语言已经使用的越来越广泛,C语言作...... 汇编语言程序设计练习题一、单项选择题:在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。1.CPU要访问的某一存...... C语言程序设计心得体会在设计打字游戏的过程中,通过我们小组各成员之间的相互讨论和合作,我们完成了打字练习的程序设计。在这个学期中,我们已经学习了《C 语言程序设计》这门......