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
Programming Articles
Page 987 of 2547
Print numbers in descending order along with their frequencies
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 MorePrint prime numbers from 1 to N in reverse order
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 MorePrint first N terms of series (0.25, 0.5, 0.75, ...) in fraction representation
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 MorePrint uncommon elements from two sorted arrays
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 MorePrint missing elements that lie in range 0 – 99
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 MorePrint the given 3 string after modifying and concatenating
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 MorePrint number of words, vowels and frequency of each character
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 MorePrint n numbers such that their sum is a perfect square
Given n numbers, we need to find n numbers whose sum is a perfect square. The solution uses the first n odd numbers, as the sum of first n odd numbers is always n². Input : 5 Output : 1 3 5 7 9 1+3+5+7+9=25 i.e (5)² Syntax for(i = 1; i
Read MoreC Program for Find largest prime factor of a number?
In this section, we will see how we can get the largest prime factor of a number in an efficient way. There is a number say n = 1092, we have to get the largest prime factor of this. The prime factors of 1092 are 2, 2, 3, 7, 13. So the largest is 13. To solve this problem, we have to follow this rule − When the number is divisible by 2, then store 2 as largest, and divide the number by 2 repeatedly. Now the number must be odd. Now starting from 3 to square root ...
Read MoreC Program for Extended Euclidean algorithms?
The Extended Euclidean Algorithm is used to find the greatest common divisor (GCD) of two integers along with the coefficients x and y such that − ax + by = gcd(a, b) This algorithm extends the standard Euclidean algorithm by not only computing the GCD but also finding the linear combination coefficients. It uses the recursive relation gcd(a, b) = gcd(b mod a, a) while keeping track of the coefficients. Syntax int extendedGCD(int a, int b, int* x, int* y); Algorithm ExtendedEuclidean(a, b, x, y) begin ...
Read More