Problem 51

author
By Supreme2023-03-16
Problem Statement :
Define structure data type called time_struct containing three member’s integer hour, integer minute and integer second. Develop a program that would assign values to the individual number and display the time in the following format: 16: 40:51.
Code:

#include <stdio.h>

struct time_struct {
int hour;
int minute;
int second;
};

int main() {

/*51. Define structure data type called time_struct containing three member’s integer hour,
integer minute and integer second. Develop a program that would assign values to the
individual number and display the time in the following format: 16: 40:51*/

printf("\tTime\n");
printf("====================");

struct time_struct current_time;
current_time.hour = 16;
current_time.minute = 40;
current_time.second = 51;

printf("\n\nCurrent Time:\n");
printf("%02d : %02d : %02d\n", current_time.hour, current_time.minute, current_time.second);

return 0;
}

Description :
  • This program defines a structure data type called time_struct with three integer members: hour, minute, and second. Then, it creates a variable of this structure type called current_time and assigns it the values of 16 hours, 40 minutes, and 51 seconds.
  • Finally, it prints the time in the following format: "16 : 40 : 51" using the printf() function with the format specifier %02d to ensure that each field has two digits and leading zeros if necessary.
  • In summary, this program demonstrates how to define and use a structure to represent and manipulate time values.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.