本题要求实现函数,可以返回一个给定月份的英文名称。函数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;
}
char *getmonth( int n )
{
int flag = 0;
char *a[12] = { "January", "February", "March", "April", "May", "June", "July","August","September","October","November","December" };
if (n >= 1 && n <= 12)
{
return a[n-1];
}
return NULL;
}
原文:https://www.cnblogs.com/2313942750qq/p/15087331.html