In this tutorial you will learn about the C Program to Print Good Morning Evening Night according to Time and its application with practical example.
C Program to Print Good Morning Evening Night according to Time
In this tutorial, we will learn to create a C program that will Print Good Morning Evening Night according to Time in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional Statements in c programming.
A program that will Print Good Morning, Evening, Night according to Time
As we all know the C programming is a very powerful programming language.With the help of which we can take input in all datatypes. In today’s program, we will create a c program that will take the input in the form of an integer, and then it will calculate the time and Print Good Morning, Evening, Night according to Time.
Algorithm:-
With the help of this program, we can Print Good Morning, Evening, Night according to Time.
1 2 3 4 5 6 7 8 9 10 11 |
1. Declare the variables for the program. 2. Take the input time from the user. 3. Pass that time to a conditional statement. 4. Calculating the time. 5. Print the greeting message. 6. End the program. |
Program to Print Good Morning Evening Night according to Time:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include<stdio.h> int main() { //declaring the variable for the program to take the input time int t; //taking input time from the user in integer form printf("Enter the time (1-24): "); scanf("%d", &t); printf("\n"); //checking the time and printing the output if(t>0 && t<=3) //printing Good night printf("Good Night"); else if(t>3 && t<12) //printing Good morning printf("Good Morning"); else if(t==12) //printing Good NOON printf("Good Noon"); else if(t>12 && t<=15) //printing Good afternoon printf("Good AfterNoon"); else if(t>15 && t<20) //printing Good EVENING printf("Good Evening"); else if(t>=20 && t<=24) printf("Good Night"); else //printing DEFAULT TIME printf("Unknown time!"); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- t = it will hold the integer value for time input.
Input strings from the user.
