/* day of the year * Author: rahule@cse.iitk.ac.in * Created on 13 August, 2010, 7:05 PM */ #include int main() { int day,month,total; printf("\nEnter the month and day :"); //Scans month and date scanf("%d%d",&month,&day); if(month==1) //checks whether the month is Jan { total=day; } else { if(month==2) //Check whether the mont is Feb total=day+31; else { if(month<=7) //checks whether the month is,or before, july total=((month)/2)*31+((month-1)/2-1)*30+28+day; //formula to calculate number of days else //checks whether the mont his afyter july month=month-7; total=212+((month)/2)*31+((month-1)/2)*30+day; //there are 212 days till august.this formula calculetes number of days from "august 1 to the required date,and adds 212 to it. } } printf("\ntotal number of days:%d\n",total); //Prints the number of days }