Program to convert weeks to days Last Updated : 12 Feb, 2024 Comments Improve Suggest changes Like Article Like Report Given no of weeks. Write a program to convert weeks to days. Examples: Input: weeks = 4Output: 28 days Input: weeks = 2Output: 14 days Approach: To solve the problem, follow the below idea: Since we know a week has 7 days. So, to find no of days in a week, we multiply weeks by 7. 1 week = 7 daysn weeks = n*7 days Below is the implementation of the above approach: C++ #include <iostream> using namespace std; int convertWeeksToDays(int weeks) { if (weeks < 0) return -1; // Convert weeks to days (1 week = 7 days) return weeks * 7; } int main() { int weeks = 9; int days = convertWeeksToDays(weeks); if (days == -1) { cout << "Invalid Input" << endl; } else { // Display the result cout << weeks << " weeks is equal to " << days << " days." << endl; } return 0; } Java public class WeekToDayConverter { // Function to convert weeks to days public static int convertWeeksToDays(int weeks) { // Check for invalid input (negative weeks) if (weeks < 0) { return -1; } // Convert weeks to days (1 week = 7 days) return weeks * 7; } public static void main(String[] args) { // Given weeks int weeks = 9; // Call the function to convert weeks to days int days = convertWeeksToDays(weeks); // Check for invalid input and display the result if (days == -1) { System.out.println("Invalid Input"); } else { System.out.println(weeks + " weeks is equal to " + days + " days."); } } } Python3 def convert_weeks_to_days(weeks): # Check for invalid input (negative weeks) if weeks < 0: return -1 # Convert weeks to days (1 week = 7 days) return weeks * 7 if __name__ == "__main__": # Given weeks weeks = 9 # Call the function to convert weeks to days days = convert_weeks_to_days(weeks) # Check for invalid input and display the result if days == -1: print("Invalid Input") else: print(f"{weeks} weeks is equal to {days} days.") C# using System; class Program { // Function to convert weeks to days static int ConvertWeeksToDays(int weeks) { if (weeks < 0) return -1; // Convert weeks to days (1 week = 7 days) return weeks * 7; } static void Main() { // Set the number of weeks int weeks = 9; // Call the function to convert weeks to days int days = ConvertWeeksToDays(weeks); if (days == -1) { Console.WriteLine("Invalid Input"); } else { // Display the result Console.WriteLine($"{weeks} weeks is equal to {days} days."); } } } JavaScript // Function to convert weeks to days function convertWeeksToDays(weeks) { if (weeks < 0) return -1; // Convert weeks to days (1 week = 7 days) return weeks * 7; } // Main function function main() { const weeks = 9; const days = convertWeeksToDays(weeks); if (days === -1) { console.log("Invalid Input"); } else { // Display the result console.log(`${weeks} weeks is equal to ${days} days.`); } } // Execute the main function main(); Output9 weeks is equal to 63 days.Time Complexity: O(1) Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Program to convert weeks to days S sumaiygs7h Follow Improve Article Tags : DSA Similar Reads 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 Find day of the week for a given date Given a date (day, month, year), the task is to determine the day of the week on which that date falls. The function should be able to compute the day for any date in the past or future. The function should return values from 0 to 6 where 0 means Sunday, 1 Monday and so on.Examples:Input: d = 30, m 12 min read Zeller's Congruence | Find the Day for a Date Zeller's congruence is an algorithm devised by Christian Zeller to calculate the day of the week for any Julian or Gregorian calendar date. It can be considered to be based on the conversion between Julian's day and the calendar date. It is an algorithm to find the day of the week for any date. For 9 min read Find the day of the week after K days from the given day Content has been removed on Authorâs request. Using Naive Approach:Approach: One approach to find the day of the week after K days from a given day is to use a brute-force method where we add K days to the given day and then find the corresponding day of the week. Algorithm: Input the day and KAdd K 3 min read Program to convert given number of days in terms of Years, Weeks and Days Given number of days, convert it in terms of Years, Week and Days. Examples : Input : 30 Output : years = 0 week = 4 days = 2 Input : 20 Output : years = 0 week = 2 days = 6 Approach : Number of years will be the quotient when number of days will be divided by 365 i.e days / 365 = years.Number of we 5 min read Like