In C programming. Program must use user defined functions and rely only on if, e
ID: 3674904 • Letter: I
Question
In C programming. Program must use user defined functions and rely only on if, else, and else if. No "for" or repetition functions. 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 futureDate(int month,int day,int year){
printf("Original Date : %d/%d/%d",month,day,year);
int Array[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int k = 63;
if(year%4==0 && (month == 1 || month ==2 ))
Array[1] = 29;
if(year%4==3 && month ==12)
Array[1] = 29;
int n = Array[month - 1] - day + Array[month%12];
int m = k - n;
int mon = (month+1)%12;
if(m>Array[(month+1)%12] ){
m = m - Array[(month+1)%12];
mon = (month+2)%12;
}
if(month > mon)
year++;
printf(" Future Date : %d/%d/%d",mon+1,m,year);
}
int main(){
int month;
int year;
int day;
printf("Enter month number:");
scanf("%d",&month);
printf("Enter day number:");
scanf("%d",&day);
printf("Enter the year:");
scanf("%d",&year);
futureDate(month,day,year);
}