20_10

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

Source Code: 

/*Write a C program to convert days into years, month and days. (Ignoring leap year and considering 1 month is 30 days)*/

#include <stdio.h>

int main()

{

int days, years, month;

printf("Enter total number of days: ");

scanf("%d", &days); 

years=0;month=0;

if(days>=365)

{

years=days/365;

days=days%365;

}

if(days>=30)

{

month=days/30;

days=days%30;

}

printf("YEARS: %d MONTH: %d DAYS: %d",  years, month, days);

return 0;

}


Or, Source Code:


#include <stdio.h>

int main()

{

int days, years, month;

printf("Enter total number of days: ");

scanf("%d", &days); 

years = (days / 365);

month = (days % 365) / 30;

days = days - ((years * 365) + (month * 30));

printf("YEARS: %d MONTH: %d DAYS: %d",  years, month, days);

return 0;

}

Output:

Write a C program to convert days into years, month and days


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...