赞
踩
KiKi想判断输入的字符是不是字母,请帮他编程实现。
多组输入,每一行输入一个字符。
针对每组输入,输出单独占一行,判断输入字符是否为字母,输出内容详见输出样例。
输入:
A
6
输出:
A is an alphabet.
6 is not an alphabet.
- #include <stdio.h>
- int main()
- {
- int n = 0;
- while (scanf("%c", &n))
- {
- if ((n >= 'A' && n <= 'Z') || (n >= 'a' && n <= 'z'))
- printf("%c is an alphabet.\n", n);
- else
- printf("%c is not an alphabet.\n",n);
- getchar();
- }
- return 0;
- }
- #include <stdio.h>
- #include <ctype.h>
- int main()
- {
- int n = 0;
- while (scanf("%c", &n))
- {
- if (isalpha(n))
- printf("%c is an alphabet.\n", n);
- else
- printf("%c is not an alphabet.\n", n);
- getchar();
- }
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int i = 0;
- int max = 0;//先初始化max,假设最大值为0
- int score = 0;
- for (i = 0; i < 3; i++)
- {
- scanf("%d", &score);
- if (score > max)
- max = score;
- }
- printf("%d\n", max);
- return 0;
- }
变种水仙花数 - Lily Number:把任意的数字,从中间拆分成两个数字,比如1461 可以拆分成(1和461), (14和61), (146和1), 如果所有拆分后的乘积之和等于自身,则是一个Lily Number。
例如:
655 = 6 * 55 + 65 * 5
1461 = 1 * 461 + 14 * 61 + 146 * 1
求出 5位数中的所有 Lily Number。
无
一行,5位数中的所有 Lily Number,每两个数之间间隔一个空格。
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int i = 0;
- for (i = 10000; i < 100000; i++)
- {
- int sum = 0;
- int j = 0;
- for (j = 1; j <= 4; j++)
- {
- int k = (int)pow(10, j);
- sum += (i % k) * (i / k);
- }
- if (sum == i)
- printf("%d ", i);
- }
- return 0;
- }

今天的经验分享就到这里,有喜欢的朋友可以点赞➕评论➕收藏➕关注,如果有不懂的地方可以咨询博主,谢谢大家支持博主!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。