easy
1 views
Print Square
Calculate and print the square of a given integer number.
Understand the Problem
Problem Statement
The program must accept a number and print its square.
Constraints
- The input number must be an integer
- The number can be positive, negative, or zero
- The square result should fit within standard integer limits
Examples
Example 1
Input
5Output
25Explanation
5 multiplied by 5 equals 25, so the square of 5 is 25.
Example 2
Input
9Output
81Explanation
9 multiplied by 9 equals 81, so the square of 9 is 81.
Solution
#include <stdio.h>
int main() {
int number;
scanf("%d", &number);
printf("%d", number * number);
return 0;
}Time:O(1)
Space:O(1)
Approach:
Read an integer using scanf, multiply it by itself, and print the result using printf.
Visual Explanation
Loading diagram...