Server Side Programming Articles

Page 959 of 2109

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 10K+ Views

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. Words such as "madam" or "racecar" or the number "10801" are palindromes. To check if a string is a palindrome, we need to compare characters from both ends moving toward the center. If the first character matches the last, second matches second-last, and so on, then the string is a palindrome. Syntax int isPalindrome(char str[]); // Returns 1 if palindrome, 0 otherwise Example 1: Using Character Comparison This approach compares characters from both ends ...

Read More

Write a program to Delete a Tree in C programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 2K+ Views

To delete a tree in C programming, we need to traverse each node and free the memory allocated to them. The key is to delete nodes in the correct order − children must be deleted before their parents to avoid memory leaks and dangling pointers. Post-order traversal is ideal for this operation as it visits children before the parent node. Syntax void deleteTree(struct node* root) { if (root == NULL) return; deleteTree(root->left); deleteTree(root->right); free(root); } How Post-order Traversal Works ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 459 Views

A function that returns 2 for input 1 and 1 for input 2 can be implemented using various approaches. This is a common programming exercise that demonstrates different logical and mathematical techniques for value swapping between two specific numbers. Syntax int functionName(int x); Method 1: Using Conditional Statement The simplest approach uses an if-else statement to check the input value and return the corresponding output − #include int reverseif(int x) { if (x == 1) return 2; ...

Read More

Write a C program to print " Tutorials Point " without using a semicolon

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 337 Views

In C programming, semicolons are statement terminators that mark the end of each statement. However, it's possible to print text without using semicolons by leveraging control structures and the return value of printf(). Syntax int printf(const char *format, ...); The printf() function returns an integer representing the number of characters printed. This return value can be used in conditional expressions within control structures that don't require semicolons. Method 1: Using if Statement The if statement can evaluate the return value of printf() without requiring a semicolon − #include int ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 742 Views

In this problem, you are given N paintings and we have M colors to paint them with. We need to find the number of ways to paint the paintings such that no two adjacent paintings have the same color. The program's output can have very large values, so we calculate the answer in standard modulo 109 + 7. Syntax long long paintWays(int n, int m); long long power(long long base, long long exp, long long mod); Mathematical Formula The formula to find the number of ways is − Ways = m ...

Read More

Surface Area and Volume of Hexagonal Prism in C programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 543 Views

The surface area of any figure is the total area that its surface covers. A hexagonal prism is a three-dimensional figure that has a hexagon at both its ends. In mathematics, a hexagonal prism is defined as a three-dimensional figure with 8 faces, 18 edges, and 12 vertices. It consists of two hexagonal bases connected by rectangular faces. a ...

Read More

Superperfect Number in C programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 619 Views

A superperfect number is a positive integer that satisfies a specific mathematical condition involving the sum of divisors function. This concept was introduced by D. Suryanarayana in 1969 as a generalization of perfect numbers. Syntax sig(sig(n)) = 2n Where sig(n) is the divisor summatory function that calculates the sum of all positive divisors of n (including 1 and n itself). Example 1: Checking if 16 is Superperfect Let's verify that 16 is a superperfect number by calculating sig(sig(16)) and comparing it with 2×16 − sig(16) = 1 + 2 + 4 ...

Read More

Super Prime in c programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 2K+ Views

A super-prime number is a prime number that occupies a prime position in the sequence of all prime numbers. For example, if we list all prime numbers as 2, 3, 5, 7, 11, 13, ..., then the super-primes are the primes at positions 2, 3, 5, 7, 11, etc. So 3 (at position 2), 5 (at position 3), and 11 (at position 5) are super-primes. Syntax void superPrimes(int n); bool sieveOfEratosthenes(int n, bool isPrime[]); Example: Finding Super-Primes Less Than 50 This program uses the Sieve of Eratosthenes to find all primes, then identifies super-primes ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 499 Views

In C programming, calculating the sum of ASCII values of each word in a sentence involves finding the ASCII value of each character and adding them up word by word. This technique is useful for text processing and string analysis tasks. Syntax int asciiValue = (int)character; // or simply int asciiValue = character; Example Here's how to calculate the sum of ASCII values for each word in a sentence − #include #include void calculateWordSums(char str[]) { int wordSum = 0; int ...

Read More

Sum triangle from an array in C programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 801 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. The new array that is formed contains 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 concept better − Array = [3, 5, 7, 8, 9] Output [106] [47, 59] [20, 27, 32] [8, 12, 15, 17] [3, 5, 7, 8, 9] Explanation For ...

Read More
Showing 9581–9590 of 21,090 articles
« Prev 1 957 958 959 960 961 2109 Next »
Advertisements