A simple cpp program to find factorial of a given number using foor loop. Input n=5 output =120 Time Complexity is O(n) //CPP program to find factorial of a given number // using for loop #include using namespace std; int main(){ int n,fact=1,i; cout<<"Enter a number:"; cin>>n; for(i=1;i<=n;i++){ fact =fact … Continue reading C++ program to find factorial of a given number

# Pratice Problem

# Java program to find Sum of proper divisor of a number

Given a natural number n, calculate sum of all its proper divisors. A proper divisor of a natural number is the divisor that is strictly less than the number. For example, number 10 has 3 proper divisors: 1, 2, 5 and the divisor summation is: 1 + 2 + 5 = 8. import java.util.*; import … Continue reading Java program to find Sum of proper divisor of a number

# All divisor of a natural number(three ways)

Given a number n, print all distinct divisors of it , including 1 and the number itself. Example: Input: n=20 output: 1 2 4 5 10 20 input n=125 output: 1 5 25 125 Method 1: A solution would be to iterate all the number from 1 to n, checking if that number divides n … Continue reading All divisor of a natural number(three ways)

# Weird Numbers

Given an integer as input, can you check the following: If N is odd then print "Weird" If N is even and, in between range 2 and 5(inclusive), print "Not Weird" If N is even and, in between range 6 and 20(inclusive), print "Weird" If is even and ,N>20 print "Not Weird" Java … Continue reading Weird Numbers

# java program that lists all the files in a given directory

java program that lists all the directory and files in a given directory import java.io.File; /** * java program that lists all the files in a given directory * Created by sani kamal on 07-May-17. */ public class FileListing { public static void main(String[] args) { String dirPath = "C:\\Program Files\\Java\\jdk1.8.0_65\\db"; File basedir = new … Continue reading java program that lists all the files in a given directory

# Tower of Hanoi implementation in java

The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower and sometimes pluralized) is a mathematical game or puzzle. It consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of … Continue reading Tower of Hanoi implementation in java

# Java Program to Implement Euclid GCD Algorithm using Recursion

The Euclidean algorithm calculates the greatest common divisor (GCD) of two number a and b. The greatest common divisor g is the largest natural number that divides both a and b without leaving a remainder. Synonyms for the GCD include the greatest common factor (GCF), the highest common factor (HCF), the highest common divisor (HCD), … Continue reading Java Program to Implement Euclid GCD Algorithm using Recursion

# java program to find n-th fibonacci number using recursion

The Fibonacci numbers are the numbers in the following integer sequence called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: The fibonacci series is defined as follows: 0,1 , 1 , 2 , 3 , 5 , 8 , 13 … Continue reading java program to find n-th fibonacci number using recursion

# Java program to find factorial of given number using recursion

Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem.One of the classic problems for introducing recursion is calculating the factorial of an integer. The factorial of any given integer — call it n — is the product of all the integers from 1 to … Continue reading Java program to find factorial of given number using recursion

# Java program to print Fibonacci sequence using array

This java program will print fibonacci sequence up to given number. if input is 5 then the program print 0 1 1 2 3