-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonthFinder.c
More file actions
42 lines (34 loc) · 738 Bytes
/
Copy pathMonthFinder.c
File metadata and controls
42 lines (34 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
//The input function
void input(int *day){
printf("Input the day number: ");
scanf("%d", day);
}
//Finding the month
int monthFinder(int day){
int m[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month = 0;
for(int j = 0; j < 12; j++){
month++;
day = day - m[j];
if(day <= 0){
month = j+1;
break;
}
}
return month;
}
//The output function
void output(int month){
printf("\nThe month is: %d\n", month);
}
int main(){
//Taking Input
int day = 0;
input(&day);
//Finding the month
int month = monthFinder(day);
//Printing the output
output(month);
return 0;
}