A. c語言轉換日期的表示形式
#include <stdio.h>
#include <string.h>
int main()
{int month,b,c;
scanf("%d/%d/%d",&month,&b,&c);
switch(month)
{
case 1:printf("Jan,%d,%d\n",b,c);
break;
case 2:printf("Feb,%d,%d\n",b,c);
break;
case 3:printf("Mar,%d,%d\n",b,c);
break;
case 4:printf("Apr,%d,%d\n",b,c);
break;
case 5:printf("May,%d,%d\n",b,c);
break;
case 6:printf("Jun,%d,%d\n",b,c);
break;
case 7:printf("Jul,%d,%d\n",b,c);
break;
case 8:printf("Aug,%d,%d\n",b,c);
break;
case 9:printf("Sep,%d,%d\n",b,c);
break;
case 10:printf("Oct,%d,%d\n",b,c);
break;
case 11:printf("Nov,%d,%d\n",b,c);
break;
case 12:printf("Dec,%d,%d\n",b,c);
break;
default:printf("Data Error\n");
}
return 0;
}
B. c語言:從鍵盤上輸入數字形式的年月日,輸出英文形式的年月日,並指出這天是星期幾.
voidmain()
{
inty,m,d,a;
scanf("%d%d%d",&y,&m,&d);
if(m==1||m==2)
{
m+=12;
y--;
}
a=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7+1;//這是一個公式,網路下就知道了。
printf("輸入的這一天是星期%d ",a);
}
C. C語言提問:將一個月份數字轉換成月份的英文名稱
#include<stdio.h>
void main()
{
int n;
char M;
do
{
printf("Please input the number of the month:\n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("您輸入的月份的英文名稱是:January\n");
break;
case 2:
printf("您輸入的月份的英文名稱是:February\n");
break;
case 3:
printf("您輸入的月份的英文名稱是:March\n");
break;
case 4:
printf("您輸入的月份的英文名稱是:April\n");
break;
case 5:
printf("您輸入的月份的英文名稱是:May\n");
break;
case 6:
printf("您輸入的月份的英文名稱是:June\n");
break;
case 7:
printf("您輸入的月份的英文名稱是:July\n");
break;
case 8:
printf("您輸入的月份的英文名稱是:Augest\n");
break;
case 9:
printf("您輸入的月份的英文名稱是:September\n");
break;
case 10:
printf("您輸入的月份的英文名稱是:October\n");
break;
case 11:
printf("您輸入的月份的英文名稱是:November\n");
break;
case 12:
printf("您輸入的月份的英文名稱是:December\n");
break;
}
printf("Do you want to continue? Input Y or not\n");
scanf(" %c",&M);
}while(M=='Y');
}