easy
0 views
Print Cube
Calculate and print the cube of a given integer
Understand the Problem
Problem Statement
The program must accept an integer N as input and print the cube of N (N³).
Example:
For input 5, the cube is 5 × 5 × 5 = 125.
Constraints
- 1 ≤ N ≤ 1000 (input range)
- N is a positive integer
- Output must be the exact cube value
Examples
Example 1
Input
5Output
125Explanation
5³ = 5 × 5 × 5 = 125
Example 2
Input
3Output
27Explanation
3³ = 3 × 3 × 3 = 27
Solution
#include <stdio.h>
int main() {
int N;
scanf("%d", &N);
printf("%d", N * N * N);
return 0;
}Time:O(1)
Space:O(1)
Approach:
1. Include standard I/O header for scanf and printf
2. Declare integer variable N to store input
3. Read N from standard input using scanf
4. Calculate and print N³ using printf with multiplication
5. Return 0 to indicate successful execution
Visual Explanation
Loading diagram...