Black Friday's verdict

Source: Internet
Author: User

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 &nbsp 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.