Google Add

Search

Find Cube Root of a Number in C, C++

Write a C, C++ program to find the cube root of a number.

In my last post, i have explained how to calculate cube of a number. In this post we'll solve very interesting problem which is finding cube root of a number.

Let's say we have give a number 125 the cube root of 125 is 5. Similarly cube root of 27 is 3.

C, C++ Interview Questions.

Programming Questions on Strings.

Find Cube Root of a Number in C++

#include <iostream>
#include <math.h>

using namespace std;

int main() {
 
 int n; 
 float result;
 
 cout << "Enter number \n";
 cin >> n;
 
 result = pow(n, 1.0/3.0);
 
 cout << "Cube of a number is " << result;
 
 return 0;
}


Find Cube Root of a Number in C

#include <stdio.h>
#include <math.h>

int main(void) {
 
 int n; 
 float result;
 
 printf ("Enter number \n");
 scanf("%d", &n);
 
 result = pow(n, 1.0/3.0);
 
 /* %f is used for float modifier */
 
 printf("Cube of a number is %f ",result);
 
 return 0;
}


Output : 

Enter number :  125

Cube of a number is 5.000000

Program to print sum of first ten numbers.

Check whether entered number is positive, negative or zero.


No comments:

Post a Comment