给定天数,将其转换为年,周和天。
例子 :
Input : 30
Output : years = 0
week = 4
days = 2
Input : 20
Output : years = 0
week = 2
days = 6
方法 :
- 年数将是天数除以365(即天数/ 365 =年)的商。
- 周数将是(Number_of_days%365)/ 7的结果。
- 天数将是(Number_of_days%365)%7的结果。
以下是实现上述方法的程序:
C
// C program to convert given
// number of days in terms of
// Years, Weeks and Days
#include
#define DAYS_IN_WEEK 7
// Function to find year,
// week, days
void find(int number_of_days)
{
int year, week, days;
// Assume that years is
// of 365 days
year = number_of_days / 365;
week = (number_of_days % 365) /
DAYS_IN_WEEK;
days = (number_of_days % 365) %
DAYS_IN_WEEK;
printf("years = %d",year);
printf("\nweeks = %d", week);
printf("\ndays = %d ",days);
}
// Driver Code
int main()
{
int number_of_days = 200;
find(number_of_days);
return 0;
}
Java
// Java program to convert given
// number of days in terms of
// Years, Weeks and Days
class GFG
{
static final int DAYS_IN_WEEK = 7;
// Function to find year, week, days
static void find(int number_of_days)
{
int year, week, days;
// Assume that years
// is of 365 days
year = number_of_days / 365;
week = (number_of_days % 365) /
DAYS_IN_WEEK;
days = (number_of_days % 365) %
DAYS_IN_WEEK;
System.out.println("years = " + year);
System.out.println("weeks = " + week);
System.out.println("days = " + days);
}
// Driver Code
public static void main(String[] args)
{
int number_of_days = 200;
find(number_of_days);
}
}
// This code is contributed by Azkia Anam.
Python3
# Python3 code to convert given
# number of days in terms of
# Years, Weeks and Days
DAYS_IN_WEEK = 7
# Function to find
# year, week, days
def find( number_of_days ):
# Assume that years is
# of 365 days
year = int(number_of_days / 365)
week = int((number_of_days % 365) /
DAYS_IN_WEEK)
days = (number_of_days % 365) % DAYS_IN_WEEK
print("years = ",year,
"\nweeks = ",week,
"\ndays = ",days)
# Driver Code
number_of_days = 200
find(number_of_days)
# This code contributed
#by "Sharad_Bhardwaj"
C#
// C# program to convert given
// number of days in terms of
// Years, Weeks and Days
using System;
class GFG
{
static int DAYS_IN_WEEK = 7;
// Function to find
// year, week, days
static void find(int number_of_days)
{
int year, week, days;
// Assume that years
// is of 365 days
year = number_of_days / 365;
week = (number_of_days % 365) /
DAYS_IN_WEEK;
days = (number_of_days % 365) %
DAYS_IN_WEEK;
Console.WriteLine("years = " +
year);
Console.WriteLine("weeks = " +
week);
Console.WriteLine("days = " +
days);
}
// Driver Code
public static void Main()
{
int number_of_days = 200;
find(number_of_days);
}
}
// This code is contributed by vt_m.
PHP
Javascript
输出 :
years = 0
weeks = 28
days = 4
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。