Days to Years Months Days in C
Q. Write a program to convert days into years months and days.
#include <stdio.h>
#include <conio.h>
void main()
{
int d, years, months, days, t;
clrscr();
printf("Enter number of days : ");
scanf("%d", &d);
years = d / 365;
t = d % 365;
months = t / 30;
days = t % 30;
printf(" %d years %d months %d days", years, months, days);
getch();
}
Q. Write an algorithm to convert days into years months and days.
START 1. Declare variables: - d (integer): total number of days input by the user - years (integer) - months (integer) - days (integer) - t (integer) : temporary variable for remainder calculations 2. Prompt the user to "Enter number of days". 3. Read the input value into variable d. 4. Calculate the number of years: years = d / 365 5. Calculate the remainder days after subtracting years: t = d % 365 6. Calculate the number of months from the remainder: months = t / 30 7. Calculate the remaining days after subtracting months: days = t % 30 8. Display the results in the format: " years months days" END
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com