数组求个数问题
希望各位大佬帮忙解答一下子{:10_303:} 本帖最后由 jackz007 于 2021-11-28 12:03 编辑#include <stdio.h>
int main(void)
{
char c ;
int n , m ;
for(n = m = 0 ; (c = getchar()) != '\n';) {
if(c >= 'A' && c <= 'Z') c += ' ' ;
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') m ++ ;
else if(c >= '0' && c <= '9') n ++ ;
}
printf("n = %d m = %d\n" , n , m) ;
}
编译、运行实况:
D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
abioekU081cEA76pr263
n = 8 m = 7
D:\00.Excise\C> 代码:#include <stdio.h>
int main()
{
int digits = 0, vowel = 0;
char arr = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};
char c;
while(1){
scanf("%c", &c);
if(c == '\n') break;
else if(c >= '0' && c <= '9') digits++;
else{
for(size_t i = 0; i < 10; i++){
if(c == arr){
vowel++;
break;
}
}
}
}
printf("digits: %d\nvowels: %d", digits, vowel);
return 0;
}输入/输出:banana12345
digits: 5
vowels: 3 ddd
页:
[1]