Initial Basics – Algebra – Problem #12

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

Problem Statement

Write a C program that does the following:  The program first takes in a 7- or 8-digit positive integer as input (that’s ensured) through the keyboard that is to be interpreted as a date in dd-mm-yyyy format. Example: 22112001 stands for November 22, 2001 and 3011987 stands for January 3, 1987. Note that the last 4 digits correspond to year, the next 2 digits correspond to month, and the next 1 or 2 digits correspond to day. Make sure that you use an integer type that can accommodate any 8-digit integer. You may use the sizeof( ) function to find out the sizes of various data types in your system.  Prints the numbers in the day, month, and year fields, each in a new line. [2]  If the year is before 2021 or after 2099, then the program prints an appropriate message and terminates. [1]  If the input integer does not correspond to any valid date (for example, 99092022, 31062078, 29022023), then the program prints an explanatory error message and terminates. If there are multiple explanations of invalidity (for example, both day and month are out of their respective ranges), any one explanation can be printed. [2]  If the input integer corresponds to a valid date, and the year is between 2021 and 2099 (both inclusive) then the program prints the month and the day (both in words) in a new line. [1+4] You may use the fact that January 1, 2021 is a Friday.

Back to Lab Problems
Initial Basics/Algebra/Problem #12

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #12

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.