C Articles

Page 71 of 96

C Program for Find largest prime factor of a number?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 3K+ Views

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 More

C Program for Extended Euclidean algorithms?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

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

C Program for efficiently print all prime factors of a given number?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 808 Views

In this section, we will see how we can get all the prime factors of a number in an efficient way. There is a number say n = 1092, we have to get all prime factors of this. The prime factors of 1092 are 2, 2, 3, 7, 13. To solve this problem, we have to follow this rule − When the number is divisible by 2, then print 2, and divide the number by 2 repeatedly. Now the number must be odd. Now starting from 3 to square root of the ...

Read More

C Program for Difference between sums of odd and even digits?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 707 Views

In C, we can find the difference between the sum of digits at odd positions and even positions in a number. The positions are counted from left to right starting at index 0. If this difference is zero, it indicates a special mathematical property. For example, in the number 156486: Even positions (0, 2, 4): 1 + 6 + 8 = 15 Odd positions (1, 3, 5): 5 + 4 + 6 = 15 Difference: 15 − 15 = 0 Syntax int checkDifference(int number); // Returns 1 if difference is zero, 0 otherwise ...

Read More

C Program for cube sum of first n natural numbers?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

In this problem we will see how we can get the sum of cubes of first n natural numbers. Here we are using one for loop that runs from 1 to n. In each step we are calculating cube of the term and then add it to the sum. This program takes O(n) time to complete. But if we want to solve this in O(1) or constant time, we can use the mathematical formula. Syntax sum = 1³ + 2³ + 3³ + ... + n³ sum = [n(n+1)/2]² Method 1: Using Loop (O(n) Time) ...

Read More

Bash program to find A to the power B?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 3K+ Views

In C programming, calculating A to the power B can be done using the built-in pow() function from the math library, or by implementing custom algorithms. The pow() function provides an easy way to compute powers of numbers. Syntax #include double pow(double base, double exponent); Method 1: Using pow() Function The pow() function from math.h calculates base raised to the power of exponent − Note: When using pow() function, you need to link the math library by adding -lm flag during compilation: gcc program.c -lm #include #include ...

Read More

Bash program to check if the Number is a Palindrome?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 4K+ Views

In C programming, to check whether a number is a palindrome, we need to reverse the number and compare it with the original. A palindrome number reads the same forwards and backwards, like 12321 or 1221. Syntax int reverseNumber(int num); int isPalindrome(int num); Method 1: Using Mathematical Approach This method extracts digits from the end and builds the reversed number mathematically − #include int reverseNumber(int num) { int reversed = 0; while (num != 0) { ...

Read More

Average of ASCII values of characters of a given string?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 948 Views

In C programming, calculating the average of ASCII values of characters in a string involves summing all character ASCII values and dividing by the string length. For example, the string "ABC" has ASCII values 65, 66, 67, giving an average of 66. Syntax float calculateAsciiAverage(char str[]); Algorithm asciiAverage(String) Begin sum := 0 for each character c in String, do sum := sum + ASCII of c done return sum/length of String End ...

Read More

Average of first n odd naturals numbers?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 326 Views

In this article, we will learn how to find the average of the first n odd natural numbers using C programming. The first n odd natural numbers are 1, 3, 5, 7, 9, ... and so on. To get the ith odd number, we can use the formula 2*i - 1 (where i starts from 1). Syntax float averageOddNumbers(int n); Algorithm Begin sum := 0 for i from 1 to n, do sum := sum + (2*i - 1) ...

Read More

ASCII NUL, ASCII 0 ('0') and Numeric literal 0?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 7K+ Views

In C programming, it's crucial to understand the difference between ASCII NUL, ASCII '0', and the numeric literal 0. These are three distinct values with different purposes and representations. Syntax char asciiNul = '\0'; // ASCII NUL (null terminator) int zero = 0; // Numeric literal 0 char zeroChar = '0'; // ASCII character '0' ASCII Values and Representations ASCII NUL ('\0') − Hexadecimal: 0x00, Decimal: 0 ASCII '0' character − Hexadecimal: ...

Read More
Showing 701–710 of 953 articles
« Prev 1 69 70 71 72 73 96 Next »
Advertisements