A simple C language programming exercise, judging black Friday, prompted to enter a year, and then give the year all the existing black Friday months, and give the number of black Friday. Judge the week by using the Caille formula.
/* * author: nonkey * time : 2015-08-02 sunday * black friday judge * Requirements: Enter a year , determine if there is a black Friday   in this year, and if so, the output has a total of * several, and the output month. * idea: Because only need to determine whether there is black Friday, so, do not have to every month every day of the calculation, Black star * period five of course only appears in 13th, so, as long as the number of years to determine the input of the year 13th whether there is a star * Five on the line, judging the week with Caille formula. * */#include <stdio.h>int main (void) {int year , moon ,day ,week ,y_in;int i ,count = 0 ;d ay = 13 ;//always judged number 13th, and the rest no matter printf (" pls input year : ") ; scanf ("%d ", &y_in) ;for (i = 1 ;i <= 12 ;i++) {if (i == 1 | | &NBSP;I&NBSP;==&NBSP;2) {moon = i + 12 ;year = y_in - 1 ;} else{moon = i ;year = y_in ;} if ((year < 1752) &Nbsp;| | (year == 1752 && moon < 9) | | (year == 1752 && moon == 9 && day < 3) week = (day + 2 * moon + 3 * (moon + 1)) &NBSP;/&NBSP;5&NBSP;+&NBSP;YEAR&NBSP;+&NBSP;YEAR&NBSP;/&NBSP;4&NBSP;+&NBSP;5) % 7 ;elseweek = (day + 2 * moon + 3 * (moon + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7 ;week++ ;//except 7 to get the number of 0--6 , need + 1 To revise to our customary 1 --7 weekday notation . if (week == 5) {count++ ;p rintf ("moon : %d\n", i) ;}} if (count == 0) {printf ("This year don ' t have black friday.\n") ;} else printf ("all black friday&Nbsp;is %d:\n ", count) ;return 0 ;}
This article is from the "Hao Shui Mo Negative Blog" blog, please be sure to keep this source http://nonkey.blog.51cto.com/6923493/1681410
Black Friday's verdict