C Articles - Page 87 of 134

Sum triangle from an array in C programming

sudhir sharma
Updated on 09-Aug-2019 11:46:46

739 Views

The sum triangle from an array is a triangle that is made by decreasing the number of elements of the array one by one and the new array that is formed is with integers that are the sum of adjacent integers of the existing array. This procedure continues until only one element remains in the array.Let's take an example to explain the content better, Array = [3, 5, 7, 8, 9]Output[106] [47, 59] [20, 27, 32] [8, 12, 15, 17] [3, 5, 7, 8, 9]ExplanationFor the first array : ( 3 + 5 = 8), ( 5 + 7 = ... Read More

C Programming for sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms

sudhir sharma
Updated on 09-Aug-2019 11:41:53

264 Views

The given series 0.6,0 .o6,.... is a geometric progression where each element is the previous element divided by 10. So find the sum of the series we have to apply the sum of GP one formula for r less than 1(r=0.1 in our case).Sum = 6/10 [1- (1/10)n/(1-1/10)] Sum = 6/9 [1- (1/10)n] Sum = 2/3[1- (1/10n)]Example#include #include int main() {    int n = 6;    float sum = 2*((1 - 1 / pow(10, n)))/3;    printf("sum = %f", sum); }Outputsum = 0.666666

C Programming for Sum of sequence 2, 22, 222, ………

sudhir sharma
Updated on 09-Aug-2019 11:40:23

1K+ Views

Given is a sequence: 2,22,222,2222….. and we need to find the sum of this sequence. So we have to Go for the mathematical formula that is made to find the sum of the series,The explanation of the formula goes in such a way that -sum =[2+22+222+2222….] sum= 2*[1+11+111+1111….] Sum = 2/9[9+99+999+9999….] sum= 2/9 [10+100+1000+10000+.....] sum = 2/9[10+102+103+104+.....] sum=2/9*[(10n-1-9n)/9]Example#include #include int main() {    int n = 3;    float sum = 2*(pow(10, n) - 1 - (9 * n))/81;    printf("sum is %d", sum);    return 0; }Outputsum is 879

Sum of the numbers up to N that are divisible by 2 or 5 in c programming

sudhir sharma
Updated on 09-Aug-2019 11:37:58

490 Views

Sum of n natural numbers that are divisible by 2 or 5 can be found by finding the sum of all natural numbers up to N that is divisible by 2 and sum of all natural numbers up to N that is divisible by 5. Adding these two sums and then subtracting it by the sum of natural numbers up to N that is divisible by 10, this gives us the desired result. This method is an efficient method that can be used to find sum up to large values of n.Some of you must be thinking of using a ... Read More

Sum of the nodes of a Singly Linked List in C Program

sudhir sharma
Updated on 09-Aug-2019 11:34:13

4K+ Views

A singly linked list is a data structure in which an element has two parts one is the value and other is the link to the next element. So to find the sum of all elements of the singly linked list, we have to navigate to each node of the linked list and add the element's value to a sum variable.For exampleSuppose we have a linked list: 2 -> 27 -> 32 -> 1 -> 5 sum = 2 + 27 + 32 + 1 + 5 = 67.This can be done by using two methods :Method 1 - Using a ... Read More

Sum of the first N terms of the series 5,12, 23, 38…. in C Programming

sudhir sharma
Updated on 09-Aug-2019 11:30:37

167 Views

To find the sum of the given series, we will analyze the series and try to get some traits that show it is known series or at least is a combination of 2 - 3 series. the given series is 5, 12, 23, 38…We have to find the sum of the series for any value of nFor exampleFor n = 3 Sum = 40.On analyzing the given series, you will find that this series is Quadratic series. In quadratic series, the difference of the numbers is in an arithmetic progression( increase by definite number)So we can directly use the formula ... Read More

Sum of the first N terms of the series 2,10, 30, 68,…. in C programming

sudhir sharma
Updated on 09-Aug-2019 11:28:04

220 Views

To find the sum of this series, we will first analyze this series.The series is:The given series is 2, 10, 30, 68…For exampleFor n = 6 Sum = 464On analysis of the given series, you will see that the series is the addition of two series first one is the series of n natural numbers and the second is the cube of n natural numbers this means the series can be split as:2, 10 , 30 ,68 = (1+13) , (2+23), (3 + 33), ( 4 + 43)so we can write the sum of the series as :sum = 2 ... Read More

Sum of the first N terms of the series 2, 6, 12, 20, 30…. in c programming

sudhir sharma
Updated on 09-Aug-2019 11:21:01

344 Views

To find the sum of this series, we will first analyze this series.The series is: 2,6,12,20,30…ExampleFor n = 6 Sum = 112 On analysis, (1+1),(2+4),(3+9),(4+16)... (1+12), (2+22), (3+32), (4+42), can be divided into two series i.e. s1:1,2,3,4,5… andS2: 12,2,32,....Find the sum of first and second using mathematical formulaSum1 = 1+2+3+4… , sum1 = n*(n+1)/2 Sum2 = 12+22+32+42… , sum1 = n*(n+1)*(2*n +1)/6Example#include int main() {    int n = 3;    int sum = ((n*(n+1))/2)+((n*(n+1)*(2*n+1))/6);    printf("the sum series till %d is %d", n,sum);    return 0; }OutputThe sum of series till 3 is 20

Sum of first n natural numbers in C Program

sudhir sharma
Updated on 01-Jul-2020 11:08:28

1K+ Views

The concept of finding the sum of sum of integers is found such that first, we will find the sum of numbers up to n and then add all the sums to get a value which will be the sum of sum which is our desired sum.For this problem, we are given a number n up to which we have to find the sum of the sum. Let's take an example to find this sum.n = 4Now we will find the sum of numbers for every number from 1 to 4 :Sum of numbers till 1 = 1 Sum of ... Read More

C Program for simple interest?

sudhir sharma
Updated on 09-Aug-2019 07:20:30

677 Views

Simple Interest is the product of principal amount, rate of interest and the time duration (in years) by 100.Example,Input − p=5, r=4, t=5Output − 1Explanation: Simple Interest = (Principal Amount * Rate of Interest * Number of years) / 100SI= 5*4*5/100 = 1Example#include #include using namespace std; int main() {    //principle amount    float p = 5;    //time    float r = 4;    //rate in years    float t = 5;    // Simple interest    float SI = 0;    SI =(p * t * r) / 100;    printf("Simple Interest = %f ",SI);    return 0; }OutputSimple Interest = 1.0000

Advertisements