|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我在 Python交流 板块看到一个 “输入年份 算天干地支生肖” 的求助帖,于是,我用C语言也写了一个,为何没有输出?
#include<stdio.h>
int main()
{
int myyear,tiangan,dizhi,shengxiao;
wchar_t tiangan_list[21] = {'庚','辛','壬','癸','甲','乙','丙','丁','戊','己'},*p1[21];
wchar_t dizhi_list[25] = {'申','酉','戌','亥','子','丑','寅','卯','辰','巳','午','未'},*p2[25];
wchar_t shengxiao_list[25] = {'鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'},*p3[25];
*p1 = tiangan_list;
*p2 = dizhi_list;
*p3 = shengxiao_list;
scanf("%d",&myyear);
tiangan = myyear % 10;
dizhi = myyear % 12;
shengxiao = (myyear % 12) - 4;
printf("%d 这一年的干支是:%c%c",myyear,*(*p1 + tiangan),*(*p2 + dizhi));
printf("生肖是属 %c\n",*(*p3 + shengxiao));
}
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main( void )
{
const wchar_t* tiangan_list = L"庚辛壬癸甲乙丙丁戊己";
const wchar_t* dizhi_list = L"申酉戌亥子丑寅卯辰巳午未";
const wchar_t* shengxiao_list = L"猴鸡狗猪鼠牛虎兔龙蛇马羊";
unsigned year;
scanf( "%u", &year );
setlocale( LC_CTYPE, "" ); // ------ 仅适用于 简体中文的windows系统 且 ……
printf( "%u 这一年的干支是:%lc%lc\n", year, tiangan_list[year%10], dizhi_list[year%12] );
printf( "生肖是属 %lc\n", shengxiao_list[year%12] );
}
|
|