Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 14 of 81

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 297 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 439 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 275 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

Print the given pattern recursively

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

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 More

Print values of 'a' in equation (a+b) <= n and a+b is divisible by x

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

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

Print n smallest elements from given array in their original order

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

Given an array of elements, the program must find the n smallest elements and display them in their original order of appearance in the array. Input : arr[] = {1, 2, 4, 3, 6, 7, 8}, k=3 Output : 1, 2, 3 Input k is 3 it means 3 smallest elements among the set needs to be displayed in original order like 1 than 2 and than 3 Syntax void findNSmallest(int arr[], int size, int k); Algorithm START Step 1 −> start variables as int i, max, pos, j, k=4 ...

Read More

Print n terms of Newman-Conway Sequence

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

The Newman-Conway Sequence is a fascinating mathematical sequence that generates integers using a recursive formula. It starts with 1, 1 and each subsequent term is calculated based on previous values in the sequence. Syntax P(n) = P(P(n - 1)) + P(n - P(n - 1)) where P(1) = P(2) = 1 Algorithm The algorithm to generate n terms of Newman-Conway sequence is − START Step 1 → Input variable n (e.g. 20) Step 2 → Initialize variables as i, p[n+1], p[1]=1, p[2]=1 Step 3 → Loop For i=3 and i

Read More

Print the kth common factor of two numbers

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

Given two numbers x and y, we need to find their kth common factor. Common factors are the numbers that divide both x and y without leaving a remainder. Syntax int findKthCommonFactor(int x, int y, int k); Algorithm The approach to find the kth common factor is − Find the smaller of the two numbers (maximum possible common factor) Iterate from 1 to the smaller number Check if the current number divides both x and y Count common factors and return when we reach the kth factor Example Let's ...

Read More

Print N lines of numbers such that every pair among numbers has a GCD K

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

In C programming, we can print N lines of numbers where every pair among the numbers has a specific GCD (Greatest Common Divisor). This involves generating sequences of numbers that maintain the required GCD property. What is GCD? GCD stands for Greatest Common Divisor of two or more integers (excluding 0). It is the largest positive integer that divides all the given numbers without remainder. For example, to find the GCD of 48 and 180 − 48 = 2 × 2 × 2 × 2 × 3 180 = 2 × 2 × 3 × ...

Read More
Showing 131–140 of 809 articles
« Prev 1 12 13 14 15 16 81 Next »
Advertisements