Find whether a given number is perfect square or not?
Duration: 5 min
This video lesson is available to enrolled students.
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This video is a programming tutorial from Knowledge Gate Eduventures, presented by instructor Yash Jain Sir, that teaches how to determine if a given positive integer is a perfect square. The lesson begins with a problem statement (Q11) displayed on a digital chalkboard, which requires a program to output 'Success' for a perfect square and 'Failure' otherwise, with test cases provided. The instructor then explains the core logic: a number is a perfect square if its square root, when converted to an integer, when squared again, equals the original number. This is demonstrated with examples like 25 (sqrt is 5, 5*5=25) and 26 (sqrt is 5.099, 5*5=25, not 26). The final part of the video shows the implementation of this logic in C code, using the `sqrt()` function from the `math.h` library, and a conditional check to validate the result. The video is structured as a step-by-step guide, moving from problem definition to logical reasoning and finally to a working code solution.
Chapters
0:00 – 2:00 00:00-02:00
The video opens with the 'KNOX MEEHEGATF' logo, which is a stylized version of 'KNOWLEDGE GATE'. It then transitions to a presentation slide for 'KNOWLEDGE GATE' with four social media handles for different educational streams. The main content begins with a problem statement (Q11) on a digital chalkboard: 'Program to find whether a number is perfect square or not.' The input is defined as 'Any integer positive number' and the output as 'Print Success if the input number is a perfect square and failure if the input number is not a perfect square.' Two public test cases are shown: Input 625, Output 'Success', and Input 1002, Output 'Failure'. The instructor, Yash Jain Sir, is visible in a small window at the bottom right, and the video is watermarked with 'clideo.com' and a copyright notice for Knowledge Gate Eduventures.
2:00 – 5:00 02:00-05:00
The instructor begins explaining the logic for solving the problem. A green box labeled 'Logic' appears on the chalkboard. He demonstrates the concept with examples: for 25, the square root is 5, and 5 squared is 25, so it is a perfect square. For 26, the square root is approximately 5.099, which is a float. He writes '26 -> 5.24 (float)' and then shows that if this float is cast to an integer, it becomes 5. He explains that the key is to check if the integer value of the square root, when squared, equals the original number. He draws a diagram showing the process: take the number, find its square root, convert it to an integer, and then square that integer to see if it matches the original number. This logic is the foundation for the code that will be written.
5:00 – 5:21 05:00-05:21
The video transitions to the 'Code' section, with a green box labeled 'Code' on the chalkboard. The instructor displays a C program. The code includes the necessary headers: `#include <stdio.h>` and `#include <math.h>`. The `main()` function is defined. Inside, two variables are declared: `int n, intvar;`. The program uses `scanf("%d", &n);` to read the input. It then calculates the square root of `n` as a double: `double floatvar = sqrt((double)n);`. The double value is then cast to an integer: `intvar = (int)floatvar;`. The core logic is implemented with an `if` statement: `if (intvar * intvar == n)`. If true, it prints "Success"; otherwise, it prints "Failure". The instructor explains this code line by line, confirming it implements the logic discussed earlier.
The video provides a comprehensive, step-by-step tutorial on solving a common programming problem. It starts by clearly defining the problem and its expected inputs and outputs. The instructor then breaks down the solution into a logical concept, using mathematical examples to illustrate the principle of checking if a number is a perfect square by comparing the square of its integer square root to the original number. This logical foundation is then directly translated into a complete, functional C program. The progression from problem statement to logical reasoning to code implementation is clear and pedagogically sound, making it an effective learning resource for students preparing for coding interviews or competitive programming.