C Articles - Page 84 of 134

C Program to Check Whether a Number is Prime or not?

sudhir sharma
Updated on 07-Nov-2023 05:31:12

42K+ Views

A prime number is a number that is divisible only by two numbers itself and one. The factor of a number is a number that can divide it.The list of the first ten prime numbers is 2, 3, 5, 7, 11, 13, 17, 23, 29, 31.A number that is not prime is a composite number. A composite number is a number that can be divided by more than two numbers.Else then prime and composite there is 1 which is neither Prime nor composite because it can be divided only by itself.How to check if a number is prime or composite ... Read More

C Program for Selection Sort?

sudhir sharma
Updated on 02-Sep-2023 11:53:29

104K+ Views

The selection sort is assaulting algorithm that works bye buy a finding the smallest number from the array and then placing it to the first position. the next array that is to be traversed will start from index next to the position where the smallest number is placed.Let's take an example to make this concept more clear.We have an array {6, 3, 8, 12, 9} in this array the smallest element is 3. So we will place 3 at the first position, after this the array will look like {3, 6, 8, 12, 9}. Now we will again find the ... Read More

C Program for Find the largest prime factor of a number?

sudhir sharma
Updated on 19-Aug-2019 07:55:07

5K+ Views

Prime Factor− In number theory, the prime factors of a positive integer are the prime numbers that divide that integer exactly. The process of finding these numbers is called integer factorization, or prime factorization.Example− Prime factors of 288 are: 288 = 2 x 2 x 2 x 2 x 2 x 3 x 3Input: n = 124 Output: 31 is the largest prime factor!ExplanationYou will find all the prime factors of a number and find the largest of them. The prime factors 124 = 2 x 2 x 31. and 31 is the largest of them.Example#include int main() { ... Read More

C/C++ Program to Find the reminder of array multiplication divided by n?

sudhir sharma
Updated on 19-Aug-2019 12:58:56

192 Views

Array multiplication we will find the product of all elements of the given array. and then according to the problem, we will divide the product with the number n. let's take an example −Input: arr[] = { 12, 35, 69, 74, 165, 54};       N = 47 Output: 14ExplanationThe array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after dividing this by 47 it will be 14.First multiple all the number then ... Read More

C/C++ Program to find the Product of unique prime factors of a number?

sudhir sharma
Updated on 19-Aug-2019 07:45:29

645 Views

The unique prime factors is a factor of the number that is a prime number too. In this problem, we have to find the product of all unique prime factors of a number. A prime number is a number that has only two factors, the number and one.Here we will try to find the best way to calculate the product of unique prime factors of a number. let's take an example to make the problem more clear.There is a number say n = 1092, we have to get the product of unique prime factors of this. The prime factors of ... Read More

C/C++ Program to the Count set bits in an integer?

sudhir sharma
Updated on 19-Aug-2019 07:43:40

255 Views

Counting set bits means counting 1’S of the given integer. For this, we have multiple solutions that can be applied. For this case, we have a binary number( binary representation of an integer), for which we have to count the number of 1’s off the string.To count the number of 1’s, we will take the string, traverse each element and count all the 1’s of the string. For example, if we input 17 the output will be 2 because the binary of 17 is 10001 that contains two 1's.Input: Enter a positive integer: 6 Output: 2ExplanationThe binary representation of 6 ... Read More

C/C++ Program to Count number of binary strings without consecutive 1’s?

sudhir sharma
Updated on 04-Aug-2025 18:35:51

365 Views

In this article, we will learn how to count all distinct binary strings of length n such that no two 1's appear consecutively. We'll explore this problem using both recursive and dynamic programming approaches in C and C++. What is a Binary String? A binary string is a sequence of characters that contains only '0' and '1'. It represents information in base-2 format. For example, "0101" is a binary string of length 4. We are given a positive integer n, and our task is to count all possible distinct binary strings of length n that do not contain ... Read More

C/C++ Program to the Count Inversions in an array using Merge Sort?

sudhir sharma
Updated on 19-Aug-2019 07:40:46

305 Views

The Count of inversions that take place to Sort the given array is known as inversion count. the inversion problem is a classical problem that can be solved using the merge sort Algorithm. in this problem v we will count all elements more than it to its left and add the count to output. ThisLogic is done inside merge function of merge sort.For understanding the topic better let us take an example. Let us consider two sub-arrays involved in merge process -  Input: arr[] = { 1, 9, 6, 4, 5} Output: Inversion count is 5ExplanationInversion count of an arrayGiven an ... Read More

C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?

sudhir sharma
Updated on 19-Aug-2019 07:35:15

418 Views

To check whether a number is divisible by 3, we add all the digits of the number and then calculate that the sum is divisible by 3 or not. In this problem, there is an array of integers arr[], and we have to check if a number formed with these number is divisible by 3. If the number formed is divisible then print ‘yes’ else print ‘no’Input: arr[] = {45, 51, 90} Output: YesExplanationconstruct a number which is divisible by 3, for example, 945510.So the answer will be Yes Find the remainder of the sum when divided by 3 true ... Read More

C/C++ Program for the Triangular Matchstick Number?

sudhir sharma
Updated on 19-Aug-2019 07:33:21

228 Views

A triangle that is made by using matchsticks arrange to make an equilateral triangle, this is called the triangular matchstick number. Triangular matchstick number is the number of matchsticks required to make the matchstick triangle.In this problem, we have the number is the floor of a matchstick pyramid, X. and our task is to write a program to print the total minimum number of matchstick required to form a pyramid of matchsticks of x floors.Let's look at an example that will make the concept more clear, Input: 7 Output: 84ExplanationThis is an extension of triangular numbers. For integer X, the ... Read More

Advertisements