Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 15 of 81

Print prime numbers with prime sum of digits in an array

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

Given an array of elements, the task is to print those numbers that are prime and whose digit sum is also prime. This problem combines prime number checking with digit sum calculation. Input: arr[]={2, 4, 3, 19, 25, 6, 11, 12, 18, 7} Output: 2, 3, 25, 11, 12, 7 The output contains numbers where both the number itself and its digit sum are prime. For example − 2, 3, 7 are prime numbers, while 25(2+5=7), 11(1+1=2), 12(1+2=3) have prime digit sums. Numbers like 19(1+9=10) are excluded because 10 is not prime. Syntax ...

Read More

Print an array with numbers having 1, 2 and 3 as a digit in ascending order

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

In this problem, we need to find and print all numbers from an array that contain the digits 1, 2, and 3. The numbers should be printed in ascending order. If no such numbers exist, we return -1. Syntax // Check if number contains digits 1, 2, and 3 int containsAllDigits(int num); // Sort and filter array elements void printNumbersWithDigits(int arr[], int n); Algorithm The approach involves the following steps − Step 1: Sort the array in ascending order Step 2: For each number, convert it to string format Step 3: ...

Read More

Print matrix in antispiral form

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

In C programming, printing a matrix in antispiral form means traversing the matrix in a spiral order (clockwise from outside to inside) and then displaying the elements in reverse order. This creates an "antispiral" pattern where we start from the center and work outward. Syntax // Using array to store spiral elements int spiral[n*n]; // Traverse in spiral order: right → down → left → up // Print in reverse order Algorithm The approach involves two main steps − Spiral Traversal: Traverse the matrix in spiral order (right → down → left ...

Read More

Print numbers in descending order along with their frequencies

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

Given an array of integer elements, the task is to arrange the elements in descending order and find their frequencies. This approach works when the input array is already sorted in ascending order. Input : arr[]={1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 7} Output : 7 occurs: 2 6 occurs: 1 5 occurs: 1 4 occurs: 1 ...

Read More

Print prime numbers from 1 to N in reverse order

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

In this article, we will learn how to print prime numbers from 1 to N in reverse order. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Our goal is to find all prime numbers in the given range from 1 to N and then print them in reverse order. For example, given N = 20, the prime numbers between 1 and 20 are: 2, 3, 5, 7, 11, 13, 17, 19. The output should be the prime numbers printed in reverse order: 19, 17, 13, 11, 7, 5, ...

Read More

Print first N terms of series (0.25, 0.5, 0.75, ...) in fraction representation

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

In C programming, printing a series like (0.25, 0.5, 0.75, ...) in fraction representation involves converting decimal values to their equivalent fractions. This series represents multiples of 0.25, which can be expressed as fractions with denominator 4. Syntax for (i = 0; i < n; i++) { // Calculate numerator and denominator // Print in fraction form: numerator/denominator } Algorithm START Step 1 → Declare variables: int num, den, i, n Step 2 → Input number in n Step 3 → Loop from i = ...

Read More

Print uncommon elements from two sorted arrays

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

Given two sorted arrays, we need to find and print all uncommon elements (elements that appear in one array but not in both). This problem uses a two-pointer technique to efficiently traverse both arrays simultaneously. Given : array1[] = {1, 4, 6, 9, 12} array2[] = {2, 4, 7, 8, 9, 10} Output : 1 2 6 7 8 10 12 Syntax void printUncommonElements(int arr1[], int n1, int arr2[], int n2); Algorithm Initialize two pointers i and j to traverse both arrays ...

Read More

Print missing elements that lie in range 0 – 99

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

In C programming, finding missing elements within a specific range is a common problem. Given an array of integers, we need to identify which numbers from 0 to 99 are missing and display them either as individual numbers or as ranges. Syntax bool flag[MAX] = { false }; for (i = 0; i < n; i++) { if (array[i] >= 0 && array[i] < 100) { flag[array[i]] = true; } } Algorithm Create a boolean array flag[100] ...

Read More

Print the given 3 string after modifying and concatenating

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

This program demonstrates how to modify multiple strings by replacing all characters with user−specified replacement characters, then concatenate the modified strings together. Syntax strlen(string) // Get string length strcat(dest, source) // Concatenate strings scanf("%s", string) // Read string input Algorithm START Step 1 → Declare three character arrays str1, str2, str3 and replacement characters ch1, ch2, ch3 Step 2 → Input the three strings and three replacement characters Step 3 → Replace all characters in str1 with ...

Read More

Print number of words, vowels and frequency of each character

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

In C programming, string analysis is a common task where we need to count words, vowels, and find the frequency of specific characters. This program demonstrates how to analyze a string by counting these different elements in a single pass. Syntax // String traversal for character analysis for(i = 0; str[i] != '\0'; i++) { // Character comparison and counting logic } Algorithm START Step 1: Declare string array, character variable, and counters (freq=0, vowels=0, words=0) Step 2: Input string and target character Step 3: Loop through each character ...

Read More
Showing 141–150 of 809 articles
« Prev 1 13 14 15 16 17 81 Next »
Advertisements