/*
编写一程序P125.C实现以下功能
从键盘读入两个字符cBegin和cEnd,要求输出≤cBegin且≥cEnd的所有字符。
编程可用素材:
printf("Please Input two char: ");
printf("\nResult: ");
程序的运行效果应类似地如图1所示,图1中的MA是从键盘输入的内容。
Please Input two char: MA
Result: MLKJIHGFEDCBA
知识点:
1. 循环起点cBegin
2. 循环终点cEnd
3. 循环趋势:越来越小
*/
#include <stdio.h>
int main(void)
{
char cBegin, cEnd;
int i;
printf("Please Input two char: ");
scanf("%c%c", &cBegin, &cEnd);
printf("\nResult: ");
for (i = (int)cBegin; i >= (int)cEnd; i--)
{
printf("%c", (char)i);
}
return 0;
}
P127
/*
编写一程序P127.C实现以下功能
从键盘读入一个字符cBegin和一个数iCount,要求输出≤cBegin的iCount个字符。
编程可用素材:
printf("Please Input a char and a number: ");
printf("\nResult: ");
程序的运行效果应类似地如图1所示,图1中的M 9是从键盘输入的内容。
Please Input a char and a number: M 9
Result: MLKJIHGFE
*/#include<stdio.h>intmain(void){
char cBegin;int iCount, i;printf("Please Input a char and a number: ");scanf("%c %i",&cBegin,&iCount);printf("\nResult: ");// 要特别注意这里的循环/*
起点:cBegin,包括端点
终点:用输入的计数来计算终点iCount个
步长:1
char类型本质上就是int型,也可以不用强转,可以自动转化的
*/for(i =(int)cBegin; i >(int)cBegin - iCount; i--){
printf("%c",(char)i);}return0;}