Tuesday, 26 December 2017

Day of the Programmer Hacker Rank Solution in C

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int days = 215; //256th days will be in 9th month so in 8 months, feb has variable days so
                //remaining 7 months days will be 215
void solve(int year){
    int febdays;
    if(year<=1917) //julian calender
        if(year%4 == 0)
            febdays=29;
        else
            febdays=28;
    else if(year == 1918)
        febdays=15;
    else
    {
        if((year%400 == 0)|| (year%4 == 0)&&(year%100 !=0))
            febdays=29;
        else
            febdays=28;
    }
    printf("%d.09.%d",256-(febdays+days),year);//febdays+days will be 8 months days
}

int main() {
    int year;
    scanf("%d", &year);
    int result_size;
    solve(year);
    return 0;
}

4 comments:

  1. How did you initialize the value of the variable 'days' by 215?

    ReplyDelete
  2. that is the sum of 7 months except feb. before sep.as every year have all those months as const.

    ReplyDelete
  3. Why did you take 15 days in year 1918

    ReplyDelete
    Replies

    1. it was because february had only 15 days on 1918

      Delete