In this tutorial you will learn about the C Program to Convert Days to Years Weeks and Days and its application with practical example.
C Program to Convert Days to Years, Weeks, and Days
In this tutorial, we will learn to create a C program that will Convert Days to Years Weeks, and Days using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the 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.
- Arithmetic operations in C Programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input days from the user. 3. Using the <strong>mathematical expressions </strong>to find the number of years and the weeks. 4. Printing the years and weeks. 5. End the Program. |
Find the Day Name of a Week:-
In today’s program, we will take the input number of days from the user. Then we will pass that variable to the mathematical expressions to find the number of weeks and years. At last, we will print the resulting years and the weeks to the user.
With the help of the below program, we can convert days to weeks and years.
Program Code:-
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 |
/* C Program to Convert Days to Years Weeks and Days */ #include <stdio.h> int main() { //declaring the required variables for the program. int days, years, weeks; //days = it will the number of days taken in input from the user. //years = it will the number of years converted. //months = it will the number of weeks converted. /* Taking the Input total number of days from user */ printf("Enter days: "); scanf("%d", &days); // Converts days to years, weeks and days years = days/365; weeks = (days % 365)/7; days = days- ((years*365) + (weeks*7)); //Printing the number of years after conversion. printf("Years: %d\n", years); //Printing the number of weeks after conversion. printf("Weeks: %d\n", weeks); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- days = it will hold the integer value for the input.
- years = it will hold the integer value.
- weeks = it will hold the integer value.
Taking the input day from the user.
Converting the days to years.
Printing output.