Write a C, C++ program to calculate cube of a number. How to find the cube of a number using C, C++ program . It's a basic programming question in which a number is input by a user and our program calculate it's cube.
How to Calculate Cube of a Number
Suppose a user has entered 5. Cube of 5 is : 5 * 5 * 5 (125) . Similarly, We can calculate cube of any number by multiplying the same number three times.
Find cube root of a number.
Calculate square of a number.
C,C++ Interview Questions.
Enter number : 5
Cube of a number is : 125
Explanation
In this program, We are taking a number as an input from a user then the cube of a number is calculated.
Basic programming questions for practice
How to Calculate Cube of a Number
Suppose a user has entered 5. Cube of 5 is : 5 * 5 * 5 (125) . Similarly, We can calculate cube of any number by multiplying the same number three times.
Find cube root of a number.
Calculate square of a number.
C,C++ Interview Questions.
C Program to Calculate Cube of a Number
#include<stdio.h> int main() { int num,cube; printf("Enter number \n"); scanf("%d",&num); /* Cube is calculated. */ cube = num * num * num; printf("Cube of a number is %d",cube); return 0; }
C Program to Find Cube of a Number using Function
#include<stdio.h> int calculateCube(int num){ /* Cube is calculated and return. */ return num * num *num; } int main() { int num,cube; printf("Enter number \n"); scanf("%d",&num); /* Cube function is called. */ cube = calculateCube(num); printf("Cube of a number is %d",cube); return 0; }
C++ Program to Calculate Cube of a Number
#include<iostream.h> using namespace std; int main() { int num, cube; cout << "Enter number \n"; cin >> num; /* Cube calculation. */ cube = num * num * num; cout << "Cube of a number is" << cube; return 0; }Output
Enter number : 5
Cube of a number is : 125
Explanation
In this program, We are taking a number as an input from a user then the cube of a number is calculated.
Basic programming questions for practice
Good you share this steps on how to find the cube of number by c++ programming language.
ReplyDeletehow to insert our program in any machine?please reply if any one knows.
ReplyDeleteError --int main (( {
ReplyDeleteIt should be int main()
program not applicable for n=100
ReplyDeleteInstead of int data type, You can use long int. As cube of 100 exceeded than int datatype limit.
Deleteits working. Thanks
ReplyDelete