① c語言編寫一個程序,根據用戶輸入英文名和姓先顯示姓氏,其後跟一個逗號,然後顯示名的首字母:
//先看基遲租這這代碼, 這段代碼的可讀性不高...... 注釋等會.
#include <stdio.h>
int main(void)
{
char first_initial, ch; //這代碼寫得不好, 打眼一看以為是錯的.....
printf("Enter a first and last name: ");
scanf(" %c", &first_initial); //這個是為了保旦慧存名字的第一個字元, 這樣剩下的就只剩下名的後面部分和
while (getchar() != ' '); //這樣它把名字給輸入完了, 因為姓和名中間有空搏兆格
while ((ch = getchar()) != '\n') //輸入姓.
if (ch != ' ') //這句感覺沒啥用, 因為姓不可能會有空格在裡面.
putchar(ch);
printf(", %c.\n", first_initial); //然後把剛剛保存到的名字的首字輸出.
return 0;
// 我咋感覺這代碼錯了.....因為一個getchar後面緊跟一個putchar, 就相當於是, 你在控制台里輸入一個1, 結果出來了倆1.
}
② 編寫一個用指針數組處理的C程序,實現從鍵盤輸入月份時輸出對應的英文名。
#include"stdio.h"
intmain()
{
intm;
char*months[]={"岩此讓埋January","February","March","April","May","June","July","August"粗滑迅,"September","October","November","December"};
printf("InputMonth:");
scanf("%d",&m);
printf("Themonthis:%s",*(months+m-1));
}
③ C語言 編寫程序,當輸入數月份時,顯示相應英文月份名稱。
#include<stdio.h>
int main(void){
char *month[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
int i;
printf("**************輸入0結束循環************ ");
while(1){
printf("請輸入月份號:");
scanf("%d",&i);
if(i==0){
悶局 return 0; 悄罩旁
}
啟橡 printf("該月的英文名為:%s ",month[i-1]);
}
}
④ c語言程序
#include<stdio.h>
#include<string.h>
intmain(void)
{
嘩絕旅charstr[100];
宏擾intcheck=0;
inti=0;
printf("請輸入英文名:");
scanf("%s",str);
str[0]=toupper(str[0]);/*首字母大寫*/
printf("%s ",str);
for(i=0;'