In C programming. Must use stdio.h and math.h only. Program must use user define
ID: 3675158 • Letter: I
Question
In C programming. Must use stdio.h and math.h only. Program must use user defined functions and rely only on if, else, and else if. No use of for, loops, or arrays. Thank you in advance!!
Problem: In recent years the start of spring break has taken place 9 weeks after the start of the spring semester. Given a month, day, and year determine the date that occurs 9 weeks later.
Example Execution #1 (this school year): Enter month number: 1 Enter day number: 11 Enter the year: 2016 Original Date: 1/11/2016 Future Date: 3/14/2016
Example Execution #2 (next school year): Enter month number: 1 Enter day number: 9 Enter the year: 2017 Original Date: 1/9/2017 Future Date: 3/13/2017
Example Execution #3 (dates can span years): Enter month number: 12 Enter day number: 31 Enter the year: 2015 Original Date: 12/31/2015 Future Date: 3/3/2016
Example Execution #4: Enter month number: 10 Enter day number: 30 Enter the year: 2014 Original Date: 10/30/2014 Future Date: 1/1/2015
Explanation / Answer
#include<stdio.h>
int main(){
int day,month,year;
int f_day,f_month,f_year;
printf("Enter month number: ");
scanf("%d",&month);
printf("Enter day number: ");
scanf("%d",&day);
printf("Enter the year: ");
scanf("%d",&year);
printf("Original Date: ");
printf("%d/%d/%d",month,day,year);
int leap = ((year%4)&&(year%100)&&(year%400))?0:1;
int daysOfMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int daysOfMonthLeap[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
f_year = year;
f_day = day;
f_month = month;
if(leap){
int temp = daysOfMonthLeap[(month-1)%12] + daysOfMonthLeap[month%12];
f_day = day+63-temp;
f_month = month+2;
if(f_day >= 30){
f_day = f_day - daysOfMonthLeap[f_month];
if(f_day != 0)
f_month = (f_month+1)%12;
}
if(f_month > 12){
f_month = f_month - 12;
f_year++;
}
}
else{
int temp = daysOfMonth[(month-1)%12] + daysOfMonth[month%12];
f_day = day+63-temp;
f_month = ((month+2)%12);
if(f_day >= 30){
f_day = f_day - daysOfMonth[f_month%12];
if(f_day != 0)
f_month = (f_month+1)%12;
}
if(f_month > 12){
f_month = f_month - 12;
f_year++;
}
}
printf("Future Date: ");
printf("%d/%d/%d",f_month,f_day,f_year);
}