Given two integers x and n, write a function to compute xn. We may assume that x and n are small and overflow doesn’t happen.… Read More
Tag Archives: C++ Basic Programs
Method 1 (Using Nested Loops):We can calculate power by using repeated addition. For example to calculate 5^6. 1) First 5 times add 5, we get 25. (5^2) 2)… Read More
The Fibonacci numbers are the numbers in the following integer sequence.0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….. In… Read More
Write a program to reverse the digits of an integer. Examples : Input : num = 12345 Output: 54321 Input : num = 876 Output:… Read More
Given a natural number n, print all distinct divisors of it. Examples: Input : n = 10 Output: 1 2 5 10 Input: n =… Read More
Given a number n, find the sum of first natural numbers. Examples : Input: n = 3 Output: 6 Explanation: Note that 1 + 2… Read More
A positive integer with digits a, b, c, d… is called an Armstrong number of order n if following condition is satisfied. abcd... = an… Read More
GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the largest number that divides both of them. For example GCD of… Read More
Given a number n, find sum of first n natural numbers. To calculate the sum, we will use a recursive function recur_sum().Examples : Input: 3… Read More
Given a prime number . The task is to check if it is possible to express as sum of two separate prime numbers.Note: The range of N… Read More
Given a large number N, task is to find the factorial of N using recursion. Factorial of a non-negative integer is the multiplication of all… Read More
Given a quadratic equation in the form ax2 + bx + c, find roots of it. Examples : Input : a = 1, b =… Read More
Given a positive integer N. The task is to write a C++ program to check if the number is prime or not. Definition: A prime number… Read More
A cube is a 3-dimensional box-like figure represented in the 3-dimensional plane. Cube has 6 squared-shape equal faces. Each face meets another face at 90… Read More
Given two positive integers i.e, the length and breadth of the rectangle, the task is to find the length of the Diagonal of a Rectangle.… Read More