Programming Articles

Page 980 of 2547

Print triplets with sum less than or equal to k in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 249 Views

Given an array with a set of elements, the task is to find all triplets (sets of exactly three elements) having sum less than or equal to a given value k. Input − arr[] = {1, 2, 3, 8, 5, 4}, k = 10 Output − triplets → {1, 2, 3} {1, 2, 5} {1, 2, 4} {1, 3, 5} {1, 3, 4} {1, 5, 4} {2, 3, 5} {2, 3, 4} Syntax for (i = 0; i < size-2; i++) { for (j = i+1; j < size-1; j++) { for (k = j+1; k < size; k++) { if (arr[i] + arr[j] + arr[k]

Read More

Print longest palindrome word in a sentence in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 2K+ Views

In C programming, finding the longest palindrome word in a sentence involves parsing individual words and checking if they read the same forwards and backwards. A palindrome is a word that remains identical when its characters are reversed. What is a Palindrome? A palindrome is a word or sequence that reads the same backward as forward. For example, "malayalam" is a palindrome because reversing it gives "malayalam" − the same word. Examples of palindromes: radar, level, madam, racecar Syntax int isPalindrome(char word[], int start, int end); void findLongestPalindrome(char sentence[]); Algorithm The ...

Read More

Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 294 Views

In C programming, we need to print a sequence of N zeros and M ones such that no two zeros are consecutive and no three ones are consecutive. This is a constraint satisfaction problem that requires careful arrangement of digits. Syntax // Condition to check if sequence is possible if ((m < n-1) || m >= 2 * (n + 1)) // Sequence not possible else // Generate valid sequence Algorithm The algorithm works in three main cases − Case 1: When m = ...

Read More

C Program for Print individual digits as words without using if or switch.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 432 Views

In C programming, converting individual digits of a number to their corresponding words is commonly done using if-else or switch statements. However, we can achieve this more elegantly using an array of string pointers to map each digit (0-9) to its word representation. Syntax char *digitWords[] = {"ZERO", "ONE", "TWO", ..., "NINE"}; // Access digit word using: digitWords[digit] Algorithm START Step 1 → Declare int variables num, i and array of pointers char *alpha with values {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"} Step 2 → Read or assign the ...

Read More

Print first k digits of 1/n where n is a positive integer in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 270 Views

In C programming, we need to find the first k digits of the decimal representation of 1/n without using floating-point arithmetic. This involves simulating the long division process using integer operations only. Syntax // Basic approach using modular arithmetic for(i = 0; i < k; i++) { digit = (10 * remainder) / n; remainder = (10 * remainder) % n; } Algorithm The algorithm simulates manual long division − Step 1: Initialize remainder = 1 (representing the dividend "1") Step 2: For each ...

Read More

Print multiples of Unit Digit of Given Number in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 5K+ Views

In C programming, finding multiples of the unit digit of a given number involves extracting the last digit and then finding all numbers that divide it evenly. The unit digit of any number can be obtained using the modulo operator (%) with 10. Syntax int unitDigit = number % 10; Algorithm START Step 1 → Declare variables num, unitDigit and i Step 2 → Input number num Step 3 → Store num%10 in unitDigit to fetch unit digit Step 4 → Print unitDigit Step 5 → Loop for i=2 and i

Read More

Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?

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

The program finds the area of a square inscribed in a circle which is inscribed in an equilateral triangle. When a circle is inscribed in an equilateral triangle of side length a, the radius of the circle is a/(2√3). The diameter of the inscribed circle becomes the diagonal of the square: d = 2 * r = a/√3. Using the formula for the area of a square given its diagonal (1/2) * d², we get: Area = (1/2) * (a²/3) = a²/6. ...

Read More

C vs BASH Fork bomb?

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

A fork bomb is a Denial of Service (DoS) attack that exploits the fork() system call to create an exponentially growing number of processes, eventually exhausting system resources. Both BASH and C can implement fork bombs, but they work differently. Syntax pid_t fork(void); BASH Fork Bomb The classic BASH fork bomb is a compact one-liner − :(){ :|: & };: This code works as follows: :() − Defines a function named : { :|: & } − Function body that pipes itself to itself and runs in background ...

Read More

Sum of squares of first n natural numbers in C Program?

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

In C programming, finding the sum of squares of the first n natural numbers means calculating 12 + 22 + 32 + ... + n2. This is a common mathematical problem that can be solved using different approaches. Example: For n = 5, the sum is 12 + 22 + 32 + 42 + 52 = 1 + 4 + 9 + 16 + 25 = 55 Syntax // Using loops for(int i = 1; i

Read More

Write you own Power without using multiplication(*) and division(/) operators in C Program

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

Power function is calculated using repeated multiplication i.e. 5n is 5*5*5… n times. To implement this without using multiplication(*) and division(/) operators, we will use nested loops that add numbers repeatedly to simulate multiplication. Syntax int power(int base, int exponent); Example: Using Nested Loops This approach uses nested loops where the outer loop runs for the exponent value and the inner loop performs repeated addition to simulate multiplication − #include int power(int base, int exponent) { if (exponent == 0) { ...

Read More
Showing 9791–9800 of 25,466 articles
« Prev 1 978 979 980 981 982 2547 Next »
Advertisements