- 从键盘上输入字符,将小写字母转换成大写字母。输入“ctl + z” 结束 。
#include<stdio.h> #include<stdlib.h> //从键盘上输入字符,将小写字母转换成大写字母。输入“ctl + z” 结束 int main() { char c; while (fflush(stdin),scanf_s("%c", &c) != EOF) { if (c >= 'a'&&c<='z' ) { c = c - 32; printf("%c", c); continue; } if (c >= 'A'&&c < ='Z') { printf("%c", c); continue; } else printf("error,input agian "); } printf(" "); system("pause"); return 0; }
- 从键盘上输入字符,(1)分别统计一下其中字母,数字,其他字符的个数, (2)将统计的字母,数字,其他字符的个数以柱状图的形式打印。例如
5
*****
***** 3
***** ***** 2
***** ***** *****
***** ***** *****
alp num oth
#include<stdio.h> #include<stdlib.h> typedef struct { int n; char *name; }elem; elem alp, num, oth, print[3], tmp; void paixu(elem *print) { if ((print[0].n < print[1].n) == 1) { tmp = print[0]; print[0] = print[1]; print[1] = tmp; } if ((print[0].n < print[2].n) == 1) { tmp = print[0]; print[0] = print[2]; print[2] = tmp; } if ((print[1].n < print[2].n) == 1) { tmp = print[1]; print[1] = print[2]; print[2] = tmp; } } int main() { char c; int cnt[3] = { 0 }; int i = 0, j = 0; int maxc; alp.n = 0; num.n = 0; oth.n = 0; alp.name = "alp"; num.name = "num"; oth.name = "oth"; int flag = 1; while (fflush(stdin), scanf_s("%c", &c) != EOF) { if (c >= 'a'&&c <= 'z' || c >= 'A'&&c <= 'Z') { alp.n++; printf("%c", c); continue; } else if (c >= 48 && c <= 57) { num.n++; printf("%c", c); continue; } else if (c != '