taeyounkim LOG
function that returns the day of year 본문
728x90
#include <stdio.h>
void day_of_year(int month, int day, int year)
{
int a[]={31,28,31,30,31,30,31,31,30,31,30,31};
int i;
int days=0;
for(i=1; i<month; i++){
days+=a[i-1];
}
days+=day;
if(year%4==0 && month>2){
days--; //for leap years
}
printf("%d", days);
}
int main()
{
int m, d, y;
printf("Enter day of year: ");
scanf("%d %d %d", &m, &d, &y);
day_of_year(m, d, y);
return 0;
}
728x90
'Career&Study > Coding Practice' 카테고리의 다른 글
Game of Craps code, 그리고 stackoverflow.com (0) | 2021.07.02 |
---|---|
function that returns the k(th) digit(from the right) in n(a positive integer) (0) | 2021.06.30 |
New Coding Fact_Converting a letter to upper case (0) | 2021.06.13 |
Code that prints a one-month calendar (0) | 2021.06.12 |
Checkbook Balance Program (0) | 2021.06.12 |