
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
N-th root of a number in C++
You are given the N-th root and the result of it. You need to find the number such that numberN = result.
Let's see some examples.
Input
result = 25 N = 2
Output
5
The 52 = 25. Hence the output in the above example is 5.
Input
result = 64 N = 3
Output
4
The 43 = 64. Hence the output in the above example is 4.
Algorithm
Implementation
Following is the implementation of the above algorithm in C++
#include <bits/stdc++.h> using namespace std; int getNthRoot(int result, int n) { int i = 1; while (true) { if (pow(i, n) == result) { return i; } i += 1; } } int main() { int result = 64, N = 6; cout << getNthRoot(result, N) << endl; return 0; }
Output
If you run the above code, then you will get the following result.
2
- Related Articles
- Primitive root of a prime number n modulo n in C++
- N-th Tribonacci Number in C++
- N-th polite number in C++
- N-th Fibonacci number in Python Program
- Find M-th number whose repeated sum of digits of a number is N in C++
- Find the k-th smallest divisor of a natural number N in C++
- Python Program for n-th Fibonacci number
- C Program for n-th even number
- C Program for n-th odd number
- Java Program for n-th Fibonacci number
- n-th number whose sum of digits is ten in C++
- Find the cube root of following number \n-2744
- C/C++ Program for the n-th Fibonacci number?
- Fifth root of a number in C++
- Find n-th lexicographically permutation of a strings in Python

Advertisements