Server Side Programming Articles - Page 2203 of 2650

Sum of square of first n odd numbers

sudhir sharma
Updated on 19-Aug-2019 08:40:00

3K+ Views

The series of squares of first n odd numbers takes squares of of first n odd numbers in series.The series is: 1,9,25,49,81,121…The series can also be written as − 12, 32, 52, 72, 92, 112….The sum of this series has a mathematical formula −n(2n+1)(2n-1)/ 3= n(4n2 - 1)/3Lets take an example,Input: N = 4 Output: sum =Explanation12 + 32 + 52 + 72 = 1 +9+ 25 + 49 = 84Using formula, sum = 4(4(4)2- 1)/3 = 4(64-1)/3 = 4(63)/3 = 4*21 = 84 both these methods are good but the one using mathematical formula is better because it does not use looks which reduces its time complexity.Example#include int main() {    int n = 8;    int sum = 0;    for (int i = 1; i

Sum of all subsets of a set formed by first n natural numbers

sudhir sharma
Updated on 19-Aug-2019 08:35:14

233 Views

A Set is a collection of data elements. Subset of a set is a set formed by only the elements after parent set. for example, B is A subset of a if all elements of B exist in A.Here we need to find the sum of all subsets of a set found by first n natural numbers. this means I need to find all subsets that can be formed and then adding them. Let's take an example, N = 3Set = {1, 2, 3}subsets formed = { {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3, } ... Read More

Sum of series with alternate signed squares of AP

sudhir sharma
Updated on 19-Aug-2019 08:33:11

311 Views

An arithmetic progression (AP) is a series of numbers in which the difference between two consecutive terms in the same. The difference is calculated by subtracting the second term from the first.Let's take a sample sequence to know about AP, 5, 7, 9, 11, 13, 15, . . . The common difference(d) of this arithmetic progression is 2. This means every succeeding element differs the former one by 2. The first term (a) of this series is 5.The general formula for finding the nth term is a{n} = a + (n-1)(d)In this problem, we are given an AP and we ... Read More

Sum of series 2/3 – 4/5 + 6/7 – 8/9 + …… upto n terms

sudhir sharma
Updated on 19-Aug-2019 08:30:52

495 Views

A series is a sequence of numbers that have some common traits that each number follows. There are various series defined in mathematics with sum mathematical logic or mathematical formula. In this problem we are given a series of numbers 2/3 , -4/5 , 6/7 , -8/9 , …..The general term of the series can be defined as (-1)n *(2*n)/ ((2*n)+1)To find the sum of series, we need to add each element of the given series as, 2/3 - 4/5 + 6/7 - 8/9 + ……Let's take an example, Input: 10 Output: -0.191921Explanation(2 / 3) - (4 / 5) + ... Read More

Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2

sudhir sharma
Updated on 19-Aug-2019 08:27:31

261 Views

A series is a sequence of numbers that have some common traits that each number follows. These mathematical series are defined based on some mathematical logic like every number increases by the same interval( arithmetic progression), every number is increased by the same multiple( geometric progression), and many other patterns.To find the sum of a series we need to evaluate the series and make a general formula for it. But in the series that is no common declaration that takes place so we have to go through the classical approach by adding each number of the series to a sum ... Read More

C Program to Check Whether a Number is Prime or not?

sudhir sharma
Updated on 07-Nov-2023 05:31:12

42K+ Views

A prime number is a number that is divisible only by two numbers itself and one. The factor of a number is a number that can divide it.The list of the first ten prime numbers is 2, 3, 5, 7, 11, 13, 17, 23, 29, 31.A number that is not prime is a composite number. A composite number is a number that can be divided by more than two numbers.Else then prime and composite there is 1 which is neither Prime nor composite because it can be divided only by itself.How to check if a number is prime or composite ... Read More

C Program for Selection Sort?

sudhir sharma
Updated on 02-Sep-2023 11:53:29

104K+ Views

The selection sort is assaulting algorithm that works bye buy a finding the smallest number from the array and then placing it to the first position. the next array that is to be traversed will start from index next to the position where the smallest number is placed.Let's take an example to make this concept more clear.We have an array {6, 3, 8, 12, 9} in this array the smallest element is 3. So we will place 3 at the first position, after this the array will look like {3, 6, 8, 12, 9}. Now we will again find the ... Read More

Bidirectional Search?

sudhir sharma
Updated on 19-Aug-2019 08:11:25

3K+ Views

A bidirectional search is a searching technique that runs two way. It works with two who searches that run simultaneously, first one from source too goal and the other one from goal to source in a backward direction. In in an optimal state, both the searches will meet in the middle off the data structure.The bidirectional search algorithm works on a directed graph to find the shortest path between the source(initial node) to the goal node. The two searches will start from their respective places and the algorithm stops when the two searches meet at a node.Importance of the bidirectional ... Read More

C++ Bidirectional Iterators

sudhir sharma
Updated on 19-Aug-2019 08:07:41

310 Views

The iterators that have the privilege to access the sequence of elements of a range from both the directions that are from the end and from the beginning are known as bidirectional iterators. iterators can work on data types like list map and sets.Bidirectional iterators have the same properties as forwarding iterators, with the only difference that they can also be decremented −propertyvalid expressionsIs default-constructible, copy-constructible, copy-assignable and destructibleX a;X b(a);b = a;Can be compared for equivalence using the equality/inequality operators (meaningful when both iterator values iterate over the same underlying sequence).a == ba != bCan be dereferenced as an ... Read More

Armstrong Numbers between two integers?

sudhir sharma
Updated on 19-Aug-2019 12:57:02

1K+ Views

An integer is called an Armstrong number of order n if it's every digit separate out and cubed and summed up then the sum will be same as the number i.e. abcd... = a3 + b3 + c3 + d3 + ...In case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example:153 = 13 + 53 + 33 // 153 is an Armstrong number.Input: Enter two numbers(intervals):999 9999 Output: Armstrong numbers between 999 and 9999 are: 1634 8208 9474Explanation1634 = 13+63+33+43 = 1+216+27+64 = 1634The approach implemented ... Read More

Advertisements