Find number of days in the month from a given date

Duration: 6 min

This video lesson is available to enrolled students.

Enroll to watch — TCS Preparation Live Course

AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This video is a programming tutorial that teaches how to write a C program to calculate the number of days in a given month from a user-provided date. The instructor begins by presenting the problem statement, which involves parsing a date in the format dd-mm-yyyy and finding the number of days in that month, with the simplification of ignoring leap years. The core of the lesson is a step-by-step walkthrough of a C code solution. The code uses an array to store the number of days for each month (January to December), with the value for February set to 28. The program prompts the user to enter a date, reads the input, and then uses the `strtok` function to split the date string by the hyphen delimiter. The month part is extracted, converted from a string to an integer using `atoi`, and used as an index to access the corresponding number of days from the array. The solution is then demonstrated in an online C compiler, where the user inputs a date, and the program correctly outputs the number of days in that month. The video is part of a series from 'Knowledge Gate' and is presented by an instructor named Yash Jain, who is visible in a small window throughout the lecture.

Chapters

  1. 0:00 2:00 00:00-02:00

    The video starts with the 'Knowledge Gate' logo, followed by a slide that introduces the channel's various social media handles and educational offerings like 'KG GATE & PLACEMENT PREP' and 'KG CODING'. The main content begins with a presentation slide that clearly states the problem: 'Q10: User enters date in dd-mm-yyyy find out number of days in month (for now please ignore the concept of leap year)'. The slide provides the input and output format and includes public test cases, such as 'Input: 12-03-2006' with 'Output: 31'. The instructor, Yash Jain, is visible in a small window, and the video is presented as a lecture from 'Knowledge Gate Edventures'.

  2. 2:00 5:00 02:00-05:00

    The instructor displays a C code solution on a digital blackboard. The code begins with standard includes: `#include <stdio.h>`, `#include <string.h>`. The main function is defined, and an integer array `arr` is initialized with the number of days for each month, starting with 31 for January and ending with 31 for December, with February set to 28. The code prompts the user to 'Enter date'. It declares a character array `date[11]` to store the input and a pointer `token` for string parsing. The `scanf` function reads the date string. The instructor then explains the use of `strtok` to split the date string by the hyphen delimiter. The month part is extracted, converted to an integer using `atoi`, and used to index the `arr` array to get the number of days. The final output is printed using `printf("Month has %d days", arr[i-1]);`. The instructor uses a whiteboard to draw arrows and write notes like 'dd-mm-yyyy' and 'token' to explain the logic.

  3. 5:00 5:42 05:00-05:42

    The video transitions to a screen recording of the 'GDB Online' compiler. The instructor pastes the C code into the editor. The code is successfully compiled, as indicated by the 'Compiled Successfully' message. The instructor then runs the program, and the 'Input' field appears. He types '12-03-2006' and presses enter. The program executes and correctly outputs 'Month has 31 days', demonstrating that the solution works for the given test case. The instructor confirms the result, concluding the practical demonstration of the code.

The video provides a comprehensive, step-by-step tutorial on solving a common programming problem. It begins with a clear problem definition, followed by a detailed explanation of the algorithm, which relies on a pre-defined array of month days and string parsing functions. The instructor methodically walks through the code, explaining each line and the logic behind it. The lesson is effectively concluded with a live demonstration in an online compiler, which validates the solution's correctness. This approach, combining theory, code walkthrough, and practical execution, makes the content highly educational for students learning C programming.

Loading lesson…