Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Tuesday, July 14, 2020

C program to convert days to years, week and days

C Program to convert days into years, week and days:
By Ahmad Irshad | Programming Exercises and Solutions > Program to convert dyas to years.

C Program To Convert Days Into Years,Months And  Days

Write a C program to take days as input form user and convert it to years, weeks and days. Waht is the step by step logic to covert days into years, weeks and days are given below

Before writing any program you just imagine about output screen first. Like what input to be given, and output to be displayed. Let's have a look at the below example.

  1. INPUT

  2. Please enter the number of days: 789
  OUTPUT

years = 2
Weeks = 8
Days = 3

Required knowledge for this exercise is

Logic to convert days to years, weeks & days: 

1) Print a massage to the user like "Please enter the number of days:" using printf();
2) Input number of days from user and store it in a variable days using scanf();
3) Now convert days to years, weeks and days using below farmula
years = (days / 365); // Ignoring leap year 
weeks = (days % 365) / 7; 
days = (days % 365) % 7; 
4) At last print the resltant values. that's it!


Program to convert days to years, weeks & days: 

  1. /* C program to convert days to years, weeks & days */
  2. #include <stdio.h> int main() { int days, years, weeks; /* Input total number of days from user */ printf("Please enter the number of days: "); scanf("%d", &days); /* Conversion to years, weeks & days */ years = (days / 365); // Ignoring leap year weeks = (days % 365) / 7; days = (days % 365) % 7; /* Print all resultant values */ printf("YEARS: %d\n", years); printf("WEEKS: %d\n", weeks); printf("DAYS: %d", days); return 0; }


Output:

  1. Please enter the number of days: 789
  2. YEARS = 2
  3. WEEKS = 8
  4. DAYS = 3







Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us