当前位置:网站首页>Experiment 4

Experiment 4

2020-12-06 22:03:49 Pan Zhenyu

/*

  • @Author: Pan Zhenyu
  • @Date: 2020-12-06 21:13:03
  • @LastEditTime: 2020-12-06 21:18:02
  • @LastEditors: Please set LastEditors
  • @Description: 12 hours to 24 hours
  • @FilePath: \undefinedc:\Users\ Pan Zhenyu \Desktop\ Code \Level 3、 ... and \ Experiment four 1.c */
#include<ctype.h>
int main(){
    int hour12,hour24,minute;
    char am_pm;
    printf("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:%.2d:%.2d\n",hour24,minute);

    return 0;
}

/*

  • @Author: Pan Zhenyu
  • @Date: 2020-12-06 21:18:12
  • @LastEditTime: 2020-12-06 21:22:58
  • @LastEditors: Please set LastEditors
  • @Description: Write a program to count the number of vowels in a sentence (a,e,I,o,u)
  • @FilePath: \undefinedc:\Users\ Pan Zhenyu \Desktop\ Code \Level 3、 ... and \ Experiment four 2.c */
#include<ctype.h>

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("Yuor sentence contains %d vowels.",num_vowels);
    return 0;
}

/*

  • @Author: Pan Zhenyu
  • @Date: 2020-12-06 21:23:08
  • @LastEditTime: 2020-12-06 21:27:46
  • @LastEditors: Please set LastEditors
  • @Description: Write a program , First display the last name according to the English first name and last name entered by the user , Followed by a comma , Then display the name The first letter of , Finally, add a dot :
  • @FilePath: \undefinedc:\Users\ Pan Zhenyu \Desktop\ Code \Level 3、 ... and \ Experiment four 3.c */

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;
}

版权声明
本文为[Pan Zhenyu]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201206220101212l.html