Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- when_World_War_IV_begins.c
- Beginning of World War I:
- DD.MM.YYYY.
- 28.7.1914.
- 2+8+7+1+9+1+4 = 32 -> 3+2 = 5
- Beginning of World War II:
- DD.MM.YYYY.
- 01.9.1939.
- 1+9+1+9+3+9 = 32 -> 3+2 = 5
- Beginning of World War III:
- (Beginning of a special action in Ukraine)
- DD.MM.YYYY.
- 24.2.2022.
- 2+4+2+2+0+2+2 = 14 -> 1+4 = 5
- Beginning of World War IV ?
- Critical dates are
- 07.01.2022. 16.01.2022. 25.01.2022.
- 06.02.2022. 15.02.2022. 24.02.2022.
- 05.03.2022. 14.03.2022. 23.03.2022.
- 04.04.2022. 13.04.2022. 22.04.2022.
- 03.05.2022. 12.05.2022. 21.05.2022. 30.05.2022.
- 02.06.2022. 11.06.2022. 20.06.2022. 29.06.2022.
- 01.07.2022. 10.07.2022. 19.07.2022. 28.07.2022.
- 09.08.2022. 18.08.2022. 27.08.2022.
- 08.09.2022. 17.09.2022. 26.09.2022.
- 07.10.2022. 16.10.2022. 25.10.2022.
- 06.11.2022. 15.11.2022. 24.11.2022.
- 05.12.2022. 14.12.2022. 23.12.2022.
- 06.01.2023. 15.01.2023. 24.01.2023.
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- // C function to check if a given year is leap year or not.
- // Returns 1 if year is leap, otherwise returns 0.
- // Rule 1. Every fourth year is a leap.
- // Rule 2. The exception to Rule 1 is that every hundredth year is not a leap.
- // Rule 3. The exception to Rule 2 is that every 400th year is a leap.
- int leapYear(int year){
- // Return true if year is a multiple of 4 and not multiple of 100.
- // OR year is multiple of 400.
- if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
- return 1;
- else
- return 0;
- }
- // extract digits from integer into array digits[]
- // returns the number of extracted digits
- int extract_digits_from_integer( int number, int digits[8] ){
- int i, j, number_of_digits = 0, mem;
- while( number != 0 ) {
- digits[number_of_digits++] = number % 10; // fill array digits[]
- number = number / 10;
- }
- // reverse first number_of_digits elements of array digits[]
- for ( i=0, j=number_of_digits-1; i<number_of_digits/2; i++, j-- ) {
- mem = digits[i];
- digits[i] = digits[j];
- digits[j] = mem;
- }
- return( number_of_digits );
- } // extract_digits_from_integer
- // finds the sum of the digits of a integer num until the sum is reduced to a single digit
- int reduce_sum_of_digits_to_a_single_digit( int num ){
- int sum, rem;
- while(num / 10 != 0){
- sum = 0;
- while(num != 0){
- rem = num % 10; // get the last digit of num
- sum += rem; // add rem to sum
- num = num / 10; // remove the last digit from num
- }
- num = sum;
- }
- return sum;
- } // reduce_sum_of_digits_to_a_single_digit()
- int main(void){
- int lastDay[12]={31,28,31,30,31,30,31,31,30,31,30,31};
- int digits_of_the_day[2], digits_of_the_month[2], digits_of_the_year[4];
- int number_of_day_digits, number_of_month_digits, number_of_year_digits;
- int firstYear=2022, lastYear=2050, d, m, y=firstYear;
- int i, counter_of_possible_dates=0, sum_of_date_digits, sum, rem;
- for(y=firstYear;y<=lastYear;y++){ // years
- if( leapYear(y) ) // calculation of the number of days in February
- lastDay[1]=29;
- else
- lastDay[1]=28;
- for(m=1;m<=12;m++){ // months
- for(d=1;d<=lastDay[m-1];d++){ // days
- sum_of_date_digits=0;
- sum=0;
- number_of_day_digits = extract_digits_from_integer(d,digits_of_the_day);
- number_of_month_digits = extract_digits_from_integer(m,digits_of_the_month);
- number_of_year_digits = extract_digits_from_integer(y,digits_of_the_year);
- for(i=0;i<number_of_day_digits;i++)
- sum_of_date_digits += digits_of_the_day[i];
- for(i=0;i<number_of_month_digits;i++)
- sum_of_date_digits += digits_of_the_month[i];
- for(i=0;i<number_of_year_digits;i++)
- sum_of_date_digits += digits_of_the_year[i];
- if ( reduce_sum_of_digits_to_a_single_digit(sum_of_date_digits) == 5 ){
- printf("%02d.%02d.%04d. ", d, m, y);
- counter_of_possible_dates++;
- if(counter_of_possible_dates%6==0)
- printf("\n");
- }
- } // days
- } // months
- } // years
- printf("\n\n From %d to %d there are %d possible dates. \n", firstYear, lastYear, counter_of_possible_dates);
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment