Found 1401 Articles for C

Ways to paint N paintings such that adjacent paintings don’t have same colors in C programming

sudhir sharma
Updated on 09-Aug-2019 12:04:02

642 Views

In this problem, you are given N painting and we have m color that we can make paintings with and we need to find the number of ways in which we can draw the painting such that none of the same color paintings are to each other.The program’s output can have very large values and handing these values is a bit problem so we will calculate its answer in standard modulo 109 +7.The formula to find the number ways is :Ways = n*(m-1)(n-1)Example to describe the problem, this will need the number of paintings n and number of colors m ... Read More

Surface Area and Volume of Hexagonal Prism in C programming

sudhir sharma
Updated on 09-Aug-2019 12:01:50

283 Views

The surface area of any figure is the total area that it's surface cover.A hexagonal prism is a three-dimensional figure that has a hexagon at both its ends. exam on prism looks like -In mathematics, Hexagonal prism is defined as three dimensional figure with 8 faces, 18 edges, 12 vertices.Surface Area = 3ah + 3√3*(a2) Volume = (3√3/2)a2hExample#include #include int main() {    float a = 5, h = 10;    //Logic to find the area of hexagonal prism    float Area;    Area = 6 * a * h + 3 * sqrt(3) * a * a;   ... Read More

Superperfect Number in C programming

sudhir sharma
Updated on 13-Aug-2019 07:50:54

328 Views

The concept of super perfect number is similar to the perfect number. It was found by D Suryanarayana in 1969. He generalized the super perfect number as a number that satisfies the following formula :sig(sig(n)) = 2nHere, sig(n) is the function that calculates the sum of divisors of a number, it is also known as divisor summatory function.The following example with making this concept clear to you :we need to check if the number N is a superperfect number or not:N = 16OutputyesExplanation − to check whether a number is a perfect number or not we will find the sum ... Read More

Super Prime in c programming

sudhir sharma
Updated on 13-Aug-2019 07:49:34

1K+ Views

A super-prime number is A number that occupies prime number position in the sequence of all prime numbers. also known as high order primes, These numbers occupy the position in the sequence of prime number which is equal to Prime number. some super prime numbers are 3, 5, 11, 1 7…For Example let us Find all super prime numbers less than 13 -Input 13Output3, 5, 11.Explanation − to find the super prime number less than 13 we will find all prime numbers that are less than 13. So, show all prime numbers less than 13 are 2, 3, 5, 7, 11, ... Read More

Sums of ASCII values of each word in a sentence in c programming

sudhir sharma
Updated on 09-Aug-2019 11:49:06

302 Views

The ASCII value of the ward is the integer presentation based on ASCII standards. In this problem, we are given a sentence and we have to calculate the sum of ASCII values of each word in the sentence.For this we will have to find the ASCII values of all the characters of the sentence and then add them up, this will give the sum of ASCII values of letters in this word. we have to do the same for all words and finally, we will add all the sums and give a final sum of ASCII values of each word ... Read More

Sum triangle from an array in C programming

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

572 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

170 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

260 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

Advertisements