Chapter - 4: The Loop Control Structure

Write a program to print 24 hours of the day with suitable suffixes like AM, PM, Noon and Midnight.


E
Sections
16
Exercises

A

B

C

D

E

1

2

3

4

5

6

7

8

10

11

12

13

14

15

16

9

#include<stdio.h>
#include<conio.h>
int main()
{
	int hr;
	for(hr = 0; hr < 24; hr++)
	{
		if(hr == 0)
			printf("\n12 Midnight");
		if(hr > 0 && hr < 12)
			printf("\n%d AM", hr);
		if(hr == 12)
			printf("\n%d Noon.", hr);
		if(hr > 12 && hr < 24)
			printf("\n%d PM.", hr-12);
	}
	getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo