Skip to content

Instantly share code, notes, and snippets.

@hosiboshi
Created May 2, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hosiboshi/da4bbb1a220f7c1d94032f670ce256ac to your computer and use it in GitHub Desktop.
Save hosiboshi/da4bbb1a220f7c1d94032f670ce256ac to your computer and use it in GitHub Desktop.
#include<stdio.h>
int cal(int x){
int thou,han,ten,one;
thou = x/1000;
han = (x - thou * 1000 )/100;
ten = (x - thou * 1000 - han * 100)/10;
one = (x - thou * 1000 - han * 100 - ten * 10);
return thou + han + ten + one;
}
int main(){
int jd,sum_11,sum_22,sum_33,total;
int i,j,k;
sum_11 = sum_22 = sum_33 = total = 0;
for(i = 1900; i <= 1999; i++){
for(j = 1; j <= 12; j++){
for(k = 1; k <= 31; k++){
total++;
jd = cal(i) + cal(j) + cal(k);
while(jd >= 10){
if(jd == 11){
sum_11++;
break;
}else if(jd == 22){
sum_22++;
break;
}else if(jd == 33){
sum_33++;
break;
}
jd = cal(jd);
}
if(j == 2&&k == 28)
break;
if((j == 4||j == 6||j == 9||j == 11)&&(k == 30))
break;
}
}
}
printf("1900年代のマスターナンバー11の誕生日数:%4d日、総日数%d日、確率%lf%%\n",sum_11,total,(double) sum_11/total * 100);
printf("1900年代のマスターナンバー22の誕生日数:%4d日、総日数%d日、確率%lf%%\n",sum_22,total,(double) sum_22/total * 100);
printf("1900年代のマスターナンバー33の誕生日数:%4d日、総日数%d日、確率%lf%%\n",sum_33,total,(double) sum_33/total * 100);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment