Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Sunidhi Bansal
Page 13 of 81
Print the string after the specified character has occurred given no. of times in C Program
In C programming, we often need to extract a substring after a specific character has occurred a certain number of times. This task involves scanning through a string and printing all characters after the nth occurrence of a specified character. Syntax for (i = 0; i < string_length; i++) { if (count > 0) { if (string[i] == target_char) { count--; } ...
Read MoreC Program for Print the pattern by using one loop
In C programming, printing patterns using a single loop is an interesting challenge that demonstrates the creative use of loop control statements like continue. This approach combines the functionality of nested loops into one loop by manipulating loop variables and using conditional statements. Syntax for (initialization; condition; ) { // Logic with continue statement // Manual increment of loop variable } Algorithm START Step 1 → Declare variables i and j to 0 with number of rows n = 6 Step 2 → Loop For i=1 and i
Read MorePrint triplets with sum less than or equal to k in C Program
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 MorePrint longest palindrome word in a sentence in C Program
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 MorePrint n 0s and m 1s such that no two 0s and no three 1s are together in C Program
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 MoreC Program for Print individual digits as words without using if or switch.
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 MorePrint first k digits of 1/n where n is a positive integer in C Program
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 MorePrint multiples of Unit Digit of Given Number in C Program
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 MorePrint the given pattern recursively
In C programming, we can create various patterns using recursive functions. A recursive function is one that calls itself repeatedly until a base condition is met. Here we'll learn to print a star pattern where each row contains an increasing number of stars. Syntax void printStars(int n); void printPattern(int n); Algorithm START Step 1 → function printStars(int n) If n > 0 printStars(n-1) Print * End IF End Step 2 → function printPattern(int n) ...
Read MorePrint values of 'a' in equation (a+b) <= n and a+b is divisible by x
Given an equation where we need to find values of 'a' such that a+b ≤ n and (a+b) is divisible by x. This problem involves finding all valid values of 'a' that satisfy both the sum constraint and divisibility condition. Syntax for (divisible = (b / x + 1) * x; divisible = 1) { // divisible - b gives us the value of 'a' } } Algorithm START Step 1 → Declare variables b=10, x=9, n=40 and flag=0, divisible Step ...
Read More