Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented
Input: 11:30 Output: 13:10
Input: 18:25 Output: 21:58



Given a valid 24 hour format time find the combination of the value and write a program ,do not hard..

Answer / Ratnesh Singh

In C, you can write a simple function to convert a 24-hour time format into a 12-hour AM/PM format. Here's an example:

```c
#include <stdio.h>

void hour_to_12(int hour) {
if (hour >= 0 && hour < 13)
printf("%d:00", hour);
else if (hour == 12)
printf("12:00");
else if (hour >= 13 && hour < 24) {
int new_hour = hour - 12;
printf("%d:00", new_hour);
}
}

int main() {
int hour, minute;

scanf("%d %d", &hour, &minute);
if (hour > 23 || hour < 0) {
printf("Invalid input. Please enter a valid 24-hour format time.n");
return 1;
}

hour_to_12(hour);
printf("%d:%02d", minute / 2, minute % 2 * 50);

return 0;
}
```

This program takes input in the format `HH MM` (Hours and Minutes) where HH is the hour in 24-hour format. The function `hour_to_12` converts the hour to a 12-hour AM/PM format, and the main function calculates and prints the minutes portion.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Explain goto?

1 Answers  


What is the scope of static variables in c language?

1 Answers  


What is c method?

1 Answers  


main() { static char *s[]={"black","white","yellow","voilet"}; char **ptr[]={s+3,s+2,s+1,s}, ***p; p=ptr; **++p; printf("%s",*--*++p+3); }

1 Answers  


How do you define structure?

1 Answers  


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

1 Answers   Aspire, Infogain,


What is the translation phases used in c language?

1 Answers  


dynamically allocate memory for linear array of n integers,store some elements in it and find some of them

1 Answers  


What is wrong in this statement?

1 Answers  


What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(ā€œ%d\nā€,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none

2 Answers  


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

1 Answers  


Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix

1 Answers   CLG,


Categories