User has to enter total number of days. We need to convert the total number of days into months and left-over days in coming month.
The formula to convert days into months is as follows −
Month=days/30
The logic to find left-over days for the coming month is as follows −
Days=days %30
Algorithm
Refer an algorithm given below to convert days into months and number of days.
Step 1: Start Step 2: Declare month and days Step 3: Read total number of days Step 4: Compute months months=days/30 Step 5: Compute days Days= days % 30 Step 6: Print months Step 7: Print days
Program
Following is the C program to convert days into months and number of days −
#include<stdio.h> main (){ int months, days ; printf("Enter days\n") ; scanf("%d", &days) ; months = days / 30 ; days = days % 30 ; printf("Months = %d Days = %d", months, days) ; }
Output
When the above program is executed, it produces the following result −
Enter days 456 Months = 15 Days = 6 Enter days 145 Months = 4 Days = 25