Program to convert days to weeks Last Updated : 18 Jan, 2024 Comments Improve Suggest changes Like Article Like Report Write a program to convert a given number of days to weeks. Examples: Input: 14 daysOutput: 2 weeks Input: 30 daysOutput: 4 weeks and 2 days Approach: To solve the problem, follow the below idea: Divide the given number of days by 7 to get the number of weeks. The remainder will be the remaining days. Step-by-step algorithm: Read the number of days.Calculate the number of weeks and remaining days.Display the result.Below is the implementation of the algorithm: C++ #include <iostream> using namespace std; int main() { int totalDays = 30; int weeks = totalDays / 7; int remainingDays = totalDays % 7; cout << totalDays << " days is equal to " << weeks << " weeks and " << remainingDays << " days." << endl; return 0; } C #include <stdio.h> int main() { int totalDays = 30; int weeks = totalDays / 7; int remainingDays = totalDays % 7; printf("%d days is equal to %d weeks and %d days.\n", totalDays, weeks, remainingDays); return 0; } Java public class DaysToWeeksConverter { public static void main(String[] args) { int totalDays = 30; int weeks = totalDays / 7; int remainingDays = totalDays % 7; System.out.println(totalDays + " days is equal to " + weeks + " weeks and " + remainingDays + " days."); } } Python3 total_days = 30 weeks = total_days // 7 remaining_days = total_days % 7 print(f"{total_days} days is equal to {weeks} weeks and {remaining_days} days.") C# using System; class Program { static void Main() { int totalDays = 30; int weeks = totalDays / 7; int remainingDays = totalDays % 7; Console.WriteLine( $"{totalDays} days is equal to {weeks} weeks and {remainingDays} days." ); } } JavaScript let totalDays = 30; let weeks = Math.floor(totalDays / 7); let remainingDays = totalDays % 7; console.log(`${totalDays} days is equal to ${weeks} weeks and ${remainingDays} days.`); Output30 days is equal to 4 weeks and 2 days. Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to convert days to weeks C code_r Follow Improve Article Tags : DSA Similar Reads Convert Date to Day of Week in R In this article, we are going to see different approaches to convert date to day of the week in R Programming language. The three different types of approaches to convert given dates to the day of the week in R language are as follows: Converting date to day of the week using weekdays functionConver 3 min read Converting seconds into days, hours, minutes and seconds Given an integer n(in seconds).Convert it into days, hours, minutes and seconds.Examples: Input : 369121517Output : 4272 days 5 hours 45 minutes 17 secondsInput : 129600Output : 1 days 12 hours 0 minutes 0 seconds Number of days = ? n / (24 * 3600) ? Number of Hours = ? (n % (24 * 3600)) / 3600 ? Nu 4 min read Excel Formula to Get Next Day of Week MS-Excel is a program that is part of the Microsoft Office suite. It is a multi-row and multi-column electronic spreadsheet that is used to organize data, graphically portray data(s), and conduct various calculations. It has 1048576 rows and 16383 columns, with each row and column forming a cell. Ea 3 min read How to Display Days in a Grid by Weeks in PHP? Displaying days in a grid by weeks consists of iterating over each day within a specified time range, organizing them into rows representing weeks and columns representing days of the week. Below are the approaches to display dates in a grid by weeks in PHP: Table of Content Using strtotime function 2 min read How to Get Week Numbers from Dates in R? Week number is the number of weeks within a year or in a set period. It indicates that people of different countries and organizations may have other ways to account for the weeks however, the most popular one is the ISO 8601. In this standard. When it comes to the extraction of week numbers in R, t 3 min read Like