Found 1339 Articles for C

C Program for the compound interest?

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

257 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 example,Input:p=5, r=4, t=5 Output:1.083263ExplanationCompound Interest = Principle * (1 + Rate / 100)^time CI=5*(1+4/100)^5 CI=1.083263Example#include #include using namespace std; int main() {    float p, r, t, ci;    p=5;    r=4;    t=5;    ci = p * pow((1 + r / 100), t) - p;    printf("%f", ci);    return 0; }

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

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

807 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 and print the n terms.Input:8 Output:0 1 1 2 3 5 8 13Explanation0+1=1 1+1=2 1+2=3 2+3=5Using For loop to sum of previous two terms for next termExample#include using namespace std; int main() {    int t1=0,t2=1,n,i,nextTerm;    n = 8;    for ( i = 1; i

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

277 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

557 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

924 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

418 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

220 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

291 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

Advertisements