Pogram to print number, its square and cube
- Write a program to print number, its square and cube in C
- Write a program to print number, its square and cube in C++
- Write a program to print number, its square and cube in Python
- Write a program to print number, its square and cube in PHP
- Write a program to print number, its square and cube in Java
- Write a program to print number, its square and cube in Java Script
- Write a program to print number, its square and cube in C#
Explanation:
Finding a number’s square and cube requires basic mathematical operations, such as multiplying the number by itself twice for the cube or by itself for the square. The reasoning is as follows:
Steps:
- Input the Number:
- Take a number as input.
- Calculate the Square:
- Multiply the number by itself : Square = Number x Number
- Calculate the Cube:
- Multiply the number by itself twice: Cube = Number x Number x Number
- Output the Results:
- Display or return the square and cube.
Pogram to print number, its square and cube
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h>
int main() {
int num = 5;
printf("Number: %d, Square: %d, Cube: %d\n", num, num * num, num * num * num);
return 0;
}
#include <iostream>
int main() {
int num = 5;
std::cout << "Number: " << num
<< ", Square: " << num * num
<< ", Cube: " << num * num * num << std::endl;
return 0;
}
num = 5
print(f"Number: {num}, Square: {num ** 2}, Cube: {num ** 3}")
<?php $num = 5; echo "Number: $num, Square: " . ($num ** 2) . ", Cube: " . ($num ** 3) . "\n"; ?>
public class Main {
public static void main(String[] args) {
int num = 5;
System.out.println("Number: " + num +
", Square: " + (num * num) +
", Cube: " + (num * num * num));
}
}
let num = 5;
console.log(`Number: ${num}, Square: ${num ** 2}, Cube: ${num ** 3}`);
using System;
class Program {
static void Main() {
int num = 5;
Console.WriteLine($"Number: {num}, Square: {num * num}, Cube: {num * num * num}");
}
}