Sudhir sharma has Published 1208 Articles

C/C++ Program to find the sum of elements in a given array

sudhir sharma

sudhir sharma

Updated on 19-Aug-2019 11:44:58

1K+ Views

Sum of all Array elements means add all array Elements. Suppose we have 5 Elements in array and we want to find there sum.arr[0]=1 arr[1]=2 arr[2]=3 arr[3]=4 arr[4]=5Sum off all above elements arearr[0]+arr[1]+arr[2]+arr[3]+ arr[4]=1+2+3+4+5=15Input:1, 2, 3, 4, 5 Output:15ExplanationUsing For loop to get to the every index element and taking ... Read More

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

437 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

173 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

563 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

379 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

145 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

119 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

159 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

1K+ 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

Advertisements