C Exercises: Convert specified days into years, weeks and days

C Basic Declarations and Expressions: Exercise-8 with Solution

Write a C program to convert specified days into years, weeks and days.

Pictorial Presentation:

C Programming: Convert specified days into years, weeks and days
Note: Ignore leap year.
Test Data :
Number of days : 1329

C Code:

#include <stdio.h> 
int main()
    int days, years, weeks;

    days = 1329; 

    // Converts days to years, weeks and days
    years = days/365; 
    weeks = (days % 365)/7;
    days = days- ((years*365) + (weeks*7));

    printf("Years: %d\n", years);
    printf("Weeks: %d\n", weeks);
    printf("Days: %d \n", days);

    return 0;

Sample Output:

Years: 3                                                               
Weeks: 33                                                              
Days: 3


C Programming Flowchart: Convert specified days into years, weeks and days

C Programming Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C program to display specified variables.
Next: Write a C program that accepts two integers from the user and calculate the sum of the two integers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

C Programming: Tips of the Day

Why do C and C++ compilers allow array lengths in function signatures when they're never enforced?

It is a quirk of the syntax for passing arrays to functions.

Actually it is not possible to pass an array in C. If you write syntax that looks like it should pass the array, what actually happens is that a pointer to the first element of the array is passed instead.

Since the pointer does not include any length information, the contents of your [] in the function formal parameter list are actually ignored.

Ref : https://bit.ly/3fhlvdH