C Articles - Page 83 of 134

10’s Complement of a decimal number?

sudhir sharma
Updated on 19-Aug-2019 09:16:32

3K+ Views

9’s complement and 10’s complement are used to make the arithmetic operations in digital system easier. These are used to make computational operations easier using complement implementation and usually trade hardware usage to the program.To obtain the 9’s complement of any number we have to subtract the number with (10n – 1) where n = number of digits in the number, or in a simpler manner we have to subtract each digit of the given decimal number from 9.10’s complement, it is relatively easy to find out the 10’s complement after finding out the 9’s complement of that number. We ... Read More

Average of Squares of n Natural Numbers?

sudhir sharma
Updated on 19-Aug-2019 09:10:15

285 Views

Given a number n, we need to find the average of the square of natural Numbers till n. For this we will first The squares of all the numbers till n. then we will add all these squares and divide them by the number n.Input 3 Output 4.666667Explanation12 + 22 + 32 = 1 + 4 + 9 = 14 14/3 = 4.666667Example#include using namespace std; int main() {    long n , i, sum=0 ,d;    n=3;    for(i=1;i

Add 1 to the number represented as array (Recursive Approach)?

sudhir sharma
Updated on 19-Aug-2019 08:59:09

570 Views

Given an array which is a collection of non-negative number represented as an array of digits, add 1 to the number (increment the number represented by the digits ). The digits are stored such that the most significant digit is the first element of the array.To add 1 to the number represented by digitsGiven array from the end, addition means rounding of the last no 4 to 5.If the last elements 9, make it 0 and carry = 1.For the next iteration check carry and if it adds to 10, do the same as step 2.After adding carry, make carry ... Read More

A square matrix as sum of symmetric and skew-symmetric matrix ?

sudhir sharma
Updated on 19-Aug-2019 08:43:39

954 Views

Symmetric Matrix − A matrix whose transpose is equal to the matrix itself. Then it is called a symmetric matrix.Skew-symmetric matrix − A matrix whose transpose is equal to the negative of the matrix, then it is called a skew-symmetric matrix.The sum of symmetric and skew-symmetric matrix is a square matrix. To find these matrices as the sum we have this formula.Let A be a square matrix. then, A = (½)*(A + A`)+ (½ )*(A - A`), A` is the transpose of the matrix.(½ )(A+ A`) is symmetric matrix.(½ )(A - A`) is a skew-symmetric matrix.Example#include using namespace std; ... Read More

Sum of square-sums of first n natural numbers

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

430 Views

The sum of square-sums of the first n natural numbers is finding the sum of sum of squares upto n terms. This series finds the sum of each number upto n, and adds this sums to a sum variable.The sum of square-sum of first 4 natural numbers is −sum = (12) + (12 + 22 ) + (12 + 22 + 32) + (12 + 22 + 32 + 42 ) = 1 + 5 + 14 + 30 = 50There are two methods to find the sum of square-sum of first n natural numbers.1) Using the for loop.In this ... Read More

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

Advertisements