Write a program to calculate and display the cube of a number till a given number (using for loop).
Home
/
Computer Science
/
Write a program to calculate and display the cube of a number till a given number (using for loop).
Write a program to calculate and display the cube of a number till a given number (using for loop).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
In Java,Python,C++
Explanation:
Java;
import java.util.Scanner;
public class FindingCube {
public static void main(String args[]){
int n = 5;
System.out.println("Enter a number ::");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println("Cube of the given number is "+(num*num*num));
}
}
Python;
# Python program to calculate cube of given number
# take input a number from user
num = int(input("Enter an any number: "))
# calculate cube using * operator
cb = num*num*num
# display result
print("Cube of {0} is {1} ".format(num, cb))
C++;
// C++ program to display the cube of the numbers upto a given integer
#include <iostream>
using namespace std;
int main()
{
int i, n, cube;
cout << "Input the number of terms : ";
cin >> n;
for (i = 1; i <= n; i++){
cube = i * i * i;
cout << "Number is: " << i << " and its cube is: " << cube << endl;
}
}
SIR.SIKHAYA.NA.TOH.KYU.CHAHIYE.¯\_ಠ_ಠ_/¯