輸入一個3,輸出March,輸入一個數字月份,然後對應輸出相應的英文表示,用指標陣列完成

孫style發表於2020-03-31
#include<stdio.h>
#include<string.h>
#define M 100
void fun(char (*p)[12])
{  int a;
   
   while(1)
   {
    printf("請輸入一個整數:\n");
	scanf("%d",&a);
	switch(a)
	{
	   case 1:printf("%s\n",p[0]);break;
	   case 2:printf("%s\n",p[1]);break;
	   case 3:printf("%s\n",p[2]);break;
	   case 4:printf("%s\n",p[3]);break;
	   case 5:printf("%s\n",p[4]);break;
	   case 6:printf("%s\n",p[5]);break;
	   case 7:printf("%s\n",p[6]);break;
	   case 8:printf("%s\n",p[7]);break;
	   case 9:printf("%s\n",p[8]);break;
		case 10:printf("%s\n",p[9]);break;
		case 11:printf("%s\n",p[10]);break; 
		case 12:printf("%s\n",p[11]);break;
	}
   }
}
int main()
{
	char s[12][12]={"January","February","March","April","May","June"," July","August","September","October"," November","December"};
    fun(s);
 
   return 0;
}

 

 

相關文章