>  기사  >  백엔드 개발  >  주어진 일 수를 연, 주, 일로 변환하는 C 프로그램을 작성하세요.

주어진 일 수를 연, 주, 일로 변환하는 C 프로그램을 작성하세요.

WBOY
WBOY앞으로
2023-09-01 23:45:07591검색

주어진 일 수를 연, 주, 일로 변환하는 C 프로그램을 작성하세요.

주어진 일수를 연, 주, 일로 변환하는 작업입니다.

1년의 일수 = 365라고 가정합니다.

년수 = (일수)/365

설명-: 연수는 주어진 일수를 나눈 몫이 됩니다. and 365

주수 = (일수 % 365) / 7

설명-: 일수를 365로 나눈 나머지를 모아서 일수로 나누어 주수를 구합니다. 일주일에 7시까지.

일수 = (일수 % 365) % 7

설명-: 일수는 일수를 365로 나눈 후 그 주의 일수로 나눈 나머지입니다. , 7.

Example

Input-:days = 209
Output-: years = 0
   weeks = 29
   days = 6
Input-: days = 1000
Output-: years = 2
   weeks = 38
   days = 4

Algorithm

Start
Step 1-> declare macro for number of days as const int n=7
Step 2-> Declare function to convert number of days in terms of Years, Weeks and Days
   void find(int total_days)
      declare variables as int year, weeks, days
      Set year = total_days / 365
      Set weeks = (total_days % 365) / n
      Set days = (total_days % 365) % n
      Print year, weeks and days
Step 3-> in main()
   Declare int Total_days = 209
   Call find(Total_days)
Stop

Example

라이브 데모

#include <stdio.h>
const int n=7 ;
//find year, week, days
void find(int total_days) {
   int year, weeks, days;
   // assuming its not a leap year
   year = total_days / 365;
   weeks = (total_days % 365) / n;
   days = (total_days % 365) % n;
   printf("years = %d",year);
   printf("</p><p>weeks = %d", weeks);
   printf("</p><p>days = %d ",days);
}
int main() {
   int Total_days = 209;
   find(Total_days);
   return 0;
}

Output

위 코드를 실행하면 다음과 같은 출력이 생성됩니다

years = 0
weeks = 29
days = 6

위 내용은 주어진 일 수를 연, 주, 일로 변환하는 C 프로그램을 작성하세요.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제