Found 1401 Articles for C

Arithmetic Mean in C programming

sudhir sharma
Updated on 09-Aug-2019 13:15:22

2K+ Views

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection.Basic properties of Arithmetic MeanThe mean of n numbers x1, x2, . . ., xn is x. If each observation is increased by p, the mean of the new observations is (x + p).The mean of n numbers x1, x2, . . ., xn is x. If each observation is decreased by p, the mean of the new observations is (x - p).The mean of n numbers x1, x2, . . ., xn is x. If each observation is multiplied by a nonzero ... Read More

C Program for Tower of Hanoi

sudhir sharma
Updated on 01-Jul-2020 11:35:25

13K+ Views

The tower of Hanoi is a mathematical puzzle. It consists of three rods and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top. We have to obtain the same stack on the third rod.The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules−Only one disk can be moved at a time.Each move consists of taking the upper disk from one of the stacks and ... Read More

C/C++ Program for nth Catalan Number?

sudhir sharma
Updated on 13-Aug-2019 06:45:25

453 Views

Catalan numbers are a sequence of numbers. Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects.Cn is the number of Dyck words of length 2n. A Dyck word is a string consisting of n X's and n Y's such that no initial segment of the string has more Y's than X's. For example, the following are the Dyck words of length 6XXXYYY XYXXYY XYXYXY XXYYXY XXYXYY.Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, Cn counts the number of expressions containing n pairs of parentheses which ... Read More

C Program to Multiply two Floating Point Numbers?

sudhir sharma
Updated on 01-Jul-2020 11:36:53

514 Views

Float is a shortened term for "floating-point." By definition, it's a fundamental data type built into the compiler that's used to define numeric values with floating decimal points. A floating-point type variable is a variable that can hold a real number, such as 4320.0, -3.33, or 0.01226. The floating part of the name floating point refers to the fact that the decimal point can “float”; that is, it can support a variable number of digits before and after the decimal point.floating pointCategoryTypeMinimum SizeTypical Sizefloating pointfloat4 bytes4 bytesdouble8 bytes8 byteslong double8 bytes8, 12, or 16 bytesFloating-point rangeSizeRangePrecision4 bytes±1.18 x 10-38 to ... Read More

C program to find the length of a string?

sudhir sharma
Updated on 01-Jul-2020 11:38:51

516 Views

The string is actually a one-dimensional array of characters which is terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.To find the length of a string we need to loop and count all words in the loop until the ‘\0’ character is matched.For exampleInput −naman Output − string length is 5Explanation − we need to iterate over each index of the string until reach the end of string means ‘\0’ which is the null character. Example#include #include int main() {    char string1[]={"naman"};    int i=0, length;    while(string1[i] !='\0') ... Read More

C Program to Check if all digits of a number divide it

sudhir sharma
Updated on 09-Aug-2019 12:33:53

556 Views

For a number n given, we need to find whether all digits of n divide it or not i.e. if a number is ‘xy’ then both x and y should divide it.SampleInput - 24 Output - Yes Explanation  - 24 % 2 == 0, 24 % 4 == 0Using conditional statements checking if each digit is non-zero and divides the number. We need to iterate over each digit of the number. And the check for the divisibility of the number for that number.Example#include int main(){    int n = 24;    int temp = n;    int flag=1;    while (temp > ... Read More

C Program to Check if a Given String is a Palindrome?

sudhir sharma
Updated on 09-Aug-2019 12:29:30

9K+ Views

A palindrome is a word, number, phrase, or other sequences of characters which reads the same backward as forward. Words such as madam or racecar or the number 10801 are a palindrome.For a given string if reversing the string gives the same string then we can say that the given string is a palindrome. Which means to check for the palindrome, we need to find whether the first and last, second and last-1, and so on elements are equal or not.Input − naman Output − string is a palindrome Input − tutorials point Output − string is not a palindromeIn C++ Program to ... Read More

Write a program to Delete a Tree in C programming

sudhir sharma
Updated on 09-Aug-2019 12:11:42

1K+ Views

To delete a tree we need to traverse each node of the tree and then delete each of them. this one by one delete every node of the tree and makes it empty. For this, we need to use a method that traverses the tree from bottom to up so that we can delete the lower notes first and then their parents so that no extra complexities arise. Based on the condition that we need, The postorder traversal will be the best suited And works efficiently so that our program will be optimum.The post-order for the following tree is -2-6-4-12-17-15The ... Read More

Write a function that returns 2 for input 1 and returns 1 for 2 in C programming

sudhir sharma
Updated on 09-Aug-2019 12:08:13

253 Views

A function that returns 2 for input 1 and 1 for input 2 is to be made. This function can be made in many ways based on the logic you use. The easiest way to do this is to use a conditional statement that if the number is 1 then return 2 otherwise return 1 and ways include using mathematical operations (any will do) and XOR operation.Example#include // Method 1 using the if statement int reverseif(int x) {    if (x == 1) return 2;    else return 1; } // Method 2 using the subtarction form sum of ... Read More

Write a C program to print “ Tutorials Point ” without using a semicolon

sudhir sharma
Updated on 01-Jul-2020 11:29:03

169 Views

To print any string without using a semicolon we need to find how the standard output work and why is semicolon used.The semicolon is a end of line statement that is used to tell the program that the line is ended here. The standard print statement printf used here is a method of the standard io library. Let's dig deep into the printf() method.int printf(const char *format , ...)This method returns an integer and has a set of arguments format and … . The format is a string that is printed in the output screen. And the … is the ... Read More

Advertisements