Home  >  Article  >  Backend Development  >  Translate the following into Chinese: C program to convert days to months and days

Translate the following into Chinese: C program to convert days to months and days

王林
王林forward
2023-08-27 12:57:06837browse

Translate the following into Chinese: C program to convert days to months and days

The user must enter the total number of days. We need to convert the total number of days into months and the remaining days in the next month.

The formula for converting days to months is as follows-

Month=days/30

The logic for finding the remaining days in the next month is as follows-

Days= days 0

Algorithm

Please refer to the algorithm given below to convert days to months and 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

The following is a C program to convert days to months and days -

Live demonstration

#include<stdio.h>
main (){
   int months, days ;
   printf("Enter days</p><p>") ;
   scanf("%d", &days) ;
   months = days / 30 ;
   days = days % 30 ;
   printf("Months = %d Days = %d", months, days) ;
}

Output

When When executing the above program, the following results are produced -

Enter days
456
Months = 15 Days = 6
Enter days
145
Months = 4 Days = 25

The above is the detailed content of Translate the following into Chinese: C program to convert days to months and days. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete