tech C Program To Input Week Number And Print Week Day | 2 Ways
Latest :

C Program To Input Week Number And Print Week Day | 2 Ways

C Program to Input Day Number and Print Week Day – In this specific article, we will brief in on the multiple ways to find the weekday by inputting the day number.

Suitable examples and sample programs have been added for a clear understanding for C Program To Input Week Number And Print Week Day. The compiler has been added as well where you can execute it by yourself.

The ways described finding the weekday by inputting the day number are as follows:

  • Using Standard Method
  • Using User-Defined Function
  • Using Pointers

As we all know, there are 7 days in a given week as per the Roman Calendar. Other calendars also have 7 days, however, this calendar is the most used across the world and by the scientific community as well.

C Program To Input Week Number And Print Week Day

As you can see, these are the days normally in a week namely:

  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • Sunday

In some places, Sunday is considered to be the first day of the week, whereas, in other places, Monday is considered the same.

Thus, the various methods to find the weekday in C Programming are as follows:

Using Standard Method

Output:

Using User-Defined Function

1)Read the entered week number and store it in the variable m.

2)Pass the m value to the user-defined function weekday(m).

3)If m value is >7 or less than  1 then weekday(int m ) function prints output as “Invalid input”.

If the entered week number is between 1 to 7 then it prints weekday name.

Output:

Using Pointers

1)Read the entered weekday value and pass the address of that value to the function weekday(int *m).

2)weekday() function checks the value at that address of m  is within the range 7 to 1 or not. If it is in the range then it prints the weekday otherwise, it prints output as “invalid input”.

Output:
tech
x

Check Also

C Program To Find Maximum Between Three Numbers | C Programs

C Program to find maximum between three numbers –  In this article, we will detail ...