FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
4.7k 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

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

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

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

 

Free Online Directory

...