码迷,mamicode.com
首页 > 编程语言 > 详细

c语言-猜生日算法

时间:2019-01-11 13:14:29      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:turn   answer   clu   stdio.h   mon   int   for   i++   print   


#include<stdio.h>
int main()
{
int a1[6]={1,3,5,7,9,11};
int a2[6]={2,3,6,7,10,11};
int a3[6]={4,5,6,7,12,0};
int a4[6]={8,9,10,11,12,0};
int b1[4][4]={{1,3,5,7},{9,11,13,15},{17,19,21,23},{25,27,29,31}};
int b2[4][4]={{2,3,6,7},{10,11,14,15},{18,19,22,23},{26,27,30,31}};
int b3[4][4]={{4,5,6,7},{12,13,14,15},{20,21,22,23},{28,29,30,31}};
int b4[4][4]={{8,9,10,11},{12,13,14,15},{24,25,26,27},{28,29,30,31}};
int b5[4][4]={{16,17,18,19},{20,21,22,23},{24,25,26,27},{28,29,30,31}};

int day=0,month=0;
int i,j,answer;

printf("Is your birthday in a1[6]?\n");
for(i=0;i<6;i++)
printf("%5d ",a1[i]);
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
month+=1;

printf("Is your birthday in a2[6]?\n");
for(i=0;i<6;i++)
printf("%5d ",a2[i]);
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
month+=2;

printf("Is your birthday in a3[6]?\n");
for(i=0;i<5;i++)
printf("%5d ",a3[i]);
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
month+=4;

printf("Is your birthday in a4[6]?\n");
for(i=0;i<5;i++)
printf("%5d ",a4[i]);
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
month+=8;

printf("Is your birthday in b1[4][4]?\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%5d ",b1[i][j]);
printf("\n");
}
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
day+=1;

printf("Is your birthday in b2[4][4]?\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%5d ",b2[i][j]);
printf("\n");
}
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
day+=2;

printf("Is your birthday in b3[4][4]?\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%5d ",b3[i][j]);
printf("\n");
}
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
day+=4;

printf("Is your birthday in b4[4][4]?\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%5d ",b4[i][j]);
printf("\n");
}
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
day+=8;

printf("Is your birthday in b5[4][4]?\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%5d ",b5[i][j]);
printf("\n");
}
printf("\n Please input 0 for No and 1 for Yes:");
scanf("%d",&answer);
if(answer==1)
day+=16;
printf("\n Your birthday is %d月%d日!\n",month,day);
return 0;
}

c语言-猜生日算法

标签:turn   answer   clu   stdio.h   mon   int   for   i++   print   

原文地址:https://www.cnblogs.com/mathstudysharing/p/10254428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!