Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
2.3k views
in GTU B.E. (CSE-I-Sem) Programming For Problem Solving Lab by Goeduhub's Expert (7.1k points)

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

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence || Labeled as Highest Rated Course by Udemy

Apply Coupon

2.

Complete Machine Learning & Data Science with Python| ML A-Z Apply Coupon

3.

Complete Python Programming from scratch | Python Projects Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

In this program we are going to implement a structure called time_struct containing three member’s integer hour, integer minute and integer second.

To learn about structure and union from beginning Click Here.

Example :

#include<stdio.h>
#include<conio.h>

//Declaration of structure time_struct
struct time_struct{
int hour,minute,second;
}time;
//Member time declared

void main()
{
int i;
clrscr();

//Data input from user
printf("\nEnter the time in hour, minute and second format");
scanf("%d%d%d",&time.hour,&time.minute,&time.second);

//Formating of the inserted data
if(time.minute>60 || time.second>60)
printf("\nPlease enter valid time format");
else
{
printf("\nEntered Time is :");
if(time.hour<=9 && time.minute<=9 && time.second<=9)
printf("\n0%d:0%d:0%d",time.hour,time.minute,time.second);
else if(time.hour<=9 && time.minute>9 && time.second>9)
printf("\n0%d:%d:%d",time.hour,time.minute,time.second);
else if(time.hour>9 && time.minute<=9 && time.second>9)
printf("\n%d:0%d:%d",time.hour,time.minute,time.second);
else if(time.hour>9 && time.minute>9 && time.second<=9)
printf("\n%d:%d:0%d",time.hour,time.minute,time.second);
else if(time.hour<=9 && time.minute<=9 && time.second>9)
printf("\n0%d:0%d:%d",time.hour,time.minute,time.second);
else if(time.hour<=9 && time.minute>9 && time.second<=9)
printf("\n0%d:%d:0%d",time.hour,time.minute,time.second);
else if(time.hour>9 && time.minute<=9 && time.second<=9)
printf("\n%d:0%d:0%d",time.hour,time.minute,time.second);
else
printf("\n%d:%d:%d",time.hour,time.minute,time.second);
}
getch();
}

Output :

Output of above program showing structure operations


For More GTU C Programming Lab Experiments Click Here

3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...