498,675 views
9 votes
9 votes
Write a c program that prompts a user to input the current month, day and year. store the data entered in a suitably defined structure and display the date in an appropriate manner.

User PeteUK
by
2.6k points

1 Answer

21 votes
21 votes

#include <stdio.h>

#include <time.h>

int main()

{

time_t s, val = 1;

struct tm* current_time;

s = time(NULL);

current_time = localtime(&s);

printf("Day of the month = %d\\",current_time->tm_mday);

printf("Day in this year = %d\\",current_time->tm_yday);

printf("Day in this week = %d\\",current_time->tm_wday);

printf("Month of this year = %d\\",(current_time->tm_mon + 1));

printf("Current year = %d\\",(current_time->tm_year + 1900));

printf("hour:min:sec = %02d:%02d:%02d\\",

current_time->tm_hour,

current_time->tm_min,

current_time->tm_sec);

return 0;

}

User Evan Langlois
by
2.7k points