1. Write a function named date() that accepts an integer of the form yyyymmdd, such as 20070412, then determines the corresponding month, day and year and returns these three values to the calling function. The function declarations for the date() is as below:
void date(int longd, int *year, int *month, int *day);
/*
#include
void date (int,int *, int*, int *);
int main()
{
int all,year,month,day;
printf("please enter the date in the form of yyyymmdd : ");
scanf("%d",&all);
date(all,&year,&month,&day);
printf("%d %d %d\n",day,month,year);
return 0;
}
void date (int longd,int *year, int *month, int *day)
{
*year = longd/10000;
*month = (longd - *year * 10000) / 100 ;
*day = longd - (*year * 10000 + *month * 100) ;
}
*/
2. Write a C function named yrCalc() that accepts a long integer representing the total number of days from the date 1/1/1900 and the addresses of the variables year, month and day. The function is to calculate the current year, month and day for the given number of days. Assume that each year has 365 days and each month has 30 days. The following function declaration is given:
void yearCalc(long totDays, int *year, int *month, int *day);
/*
#include
void yrCalc (int,int *, int*, int *);
int main()
{
int totDays,year,month,day;
printf("please enter the total number of days : ");
scanf("%d",&totDays);
yrCalc(totDays,&year,&month,&day);
printf("%d %d %d\n",day,month,year+1900);
return 0;
}
void yrCalc (int totDays,int *year, int *month, int *day)
{
*year = totDays / 365;
*month = (totDays - *year * 365) / 30 ;
*day = totDays - (*month * 30 + *year *365) ;
}
*/
No comments:
Post a Comment