Sudhir sharma has Published 1149 Articles

C Program for the Difference between sums of odd and even digits?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:41:47

2K+ Views

Given a number, find the difference between sum of odd digits and sum of even digits. Which means we will be count all even digits and all odd digits and the subtracting their sums.SampleInput:12345 Output:3Explanationthe odd digits is 2+4=6 the even digits is 1+3+5=9 odd-even=9-6=3Taking every digit out of number ... Read More

C Program for the cube sum of first n natural numbers?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:40:22

561 Views

The cube sum of first n natural numbers is the program to add cubes of all natural numbers up to n. It is sum of series 1^3 + 2^3 + …. + n^3 that is sum of cube of n natural numbers.Input:6 Output:441Explanation1^3 + 2^3 + 3^3 + 4^3 + ... Read More

C Program for the compound interest?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:39:05

254 Views

Compound interest is the simple interest that is compounded annually i.e. the interest will be calculated and added to the principal amount every year. This increases the overall interest as compared to simple interest. There is a different mathematical formula to calculate the compound interest. Lets see with the an ... Read More

C/C++ Program for the n-th Fibonacci number?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:37:38

806 Views

The Fibonacci sequence is a series where the next term is the sum of the previous two terms.The first two terms of the Fibonacci sequence is 0 followed by 1. In this problem, we will find the nth number in the Fibonacci series. For this we will calculate all the numbers ... Read More

C++ Program for the Recursive Bubble Sort?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:35:50

575 Views

In Bubble sort compares adjacent pairs and swaps them if they are in the wrong order. In this type of bubble sort we use the recursive function that calls itself.Input:53421 Output:12345ExplanationUse of recursive (self-calling) function compares adjacent pairs and swaps them if they are in the wrong order until the ... Read More

C++ Program for the Range sum queries without updates?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:34:19

224 Views

We need to compute sum of elements from index i to index j. The queries consisting of i and j index values will be executed multiple times.Input:arr[] = {5, 6, 3, 4, 1 } i = 1, j =3 Output: 13Explanation6 + 3 + 4 = 13 sum[] = {5, ... Read More

C++ Program for the Largest K digit number divisible by X?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:31:51

167 Views

Two integers X and K are given. K is the number of digit in integer number. The logic is to find largest K-digit number divisible by X.Input: X = 30, K = 3 Output: 980Explanation980 is the largest three digit number divisible by 30. By taking the K in power ... Read More

C++ Program for the Gnome Sort?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:30:27

218 Views

Gnome sort is a sorting algorithm which is similar to Insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort.Input: 53421 Output: 12345ExplanationSorting algorithm that moving an element to its proper place is accomplished by a series of ... Read More

C++ Program for GCD of more than two (or array) numbers?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:28:26

2K+ Views

The common divisor of two numbers are the numbers that are divisors of both of them.For example, the divisors of 12 are 1, 2, 3, 4, 6, 12. The divisors of 18 are 1, 2, 3, 6, 9, 18. Thus, the common divisors of 12 and 18 are 1, 2, ... Read More

C++ Program for the Comb Sort?

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:27:25

527 Views

Comb sort is similar to bubble sort and cocktail sort. Comb sort doesn’t start off looking at adjacent elements but instead looks at elements a certain number of indexes apart, this is called the gap. The gap is defined as [n/c] where n is the number of elements and c ... Read More

Advertisements