6-13 輸出月份英文名 (15分)


6-13 輸出月份英文名 (15分)
 

本題要求實現函數,可以返回一個給定月份的英文名稱。

函數接口定義:

char *getmonth( int n ); 
 

函數getmonth應返回存儲了n對應的月份英文名稱的字符串頭指針。如果傳入的參數n不是一個代表月份的數字,則返回空指針NULL。

裁判測試程序樣例:

#include <stdio.h> char *getmonth( int n ); int main() { int n; char *s; scanf("%d", &n); s = getmonth(n); if ( s==NULL ) printf("wrong input!\n"); else printf("%s\n", s); return 0; } /* 你的代碼將被嵌在這里 */ 
 

輸入樣例1:

5
 

輸出樣例1:

May
 

輸入樣例2:

15 
 

輸出樣例2:

wrong input!



char month[12][10]={"January","February","March", "April" ,"May" ,"June","July","August" ,"September","October","November","December" };
char *getmonth( int n )
{
 
 if(n<=0||n>12)
 {
  return NULL;
 }
 return month[n-1];
 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM