第一题
#include
#include
int main() {
int hour12,hour24,minute;
char am_pm;
putchar("Enter a 12-hour time:");
scanf("%d:%d %c",&hour12,&minute,&am_pm);
hour24=hour12%12;
if (toupper(am_pm)=='p')
hour24+=12;
printf("Equivalent 24-hour time:%d.2d:.2d\n",hour24,minute);
return 0;
}
第二题
#include
#include
int main() {
char ch;
int num_vowels=0;
printf("Enter a sentence:");
while ((ch=getchar())!='\n'){
switch (toupper(ch)) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
num_vowels++;
}
}
printf("Your sentence contains %d vowels.",num_vowels);
return 0;
}
第三题
#include
int main() {
char first_inital,ch;
printf("Enter a first and last name:");
scanf("%c",&first_inital);
while (getchar()!=' '){
while ((ch=getchar())!='\n'){
if(ch!=' ')
putchar(ch);
}
}
printf(",%c.\n",first_inital);
return 0;
}