Found 33676 Articles for Programming

Count divisors of n that have at-least one digit common with n in Java

Sunidhi Bansal
Updated on 06-Jun-2020 12:18:23

223 Views

We are given with a number let’s say, num and the task is to calculate the divisor of a given number thereby count the divisors of num that have at least one digit common with n.Input − num = 24Output − Count is 4Explanation − we will perform the following steps −Firstly, calculate the divisors of a given numberDivisors of 24 are − 1, 2, 3, 4, 6, 8, 12, 24Secondly, check which divisor have at least one digit that matches with the digits of a number2, 4, 12, 24 are the divisors that contain the digit that matches with ... Read More

Count natural numbers whose all permutation are greater than that number in C++

Sunidhi Bansal
Updated on 06-Jun-2020 12:11:50

431 Views

We are given a natural number let’s say, num and the task is to calculate the count of all those natural numbers whose all permutations are greater than that number.We are working with the following conditions −The data should be natural numbers onlyAll the possible permutations or arrangement of a natural number should be equal or greater than the given number. For example, the number is 20Consider all the numbers till 20 starting from 1 i.e. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20Now check those numbers whose arrangement or permutation is equaled or greater than the given number i.e. 20. Numbers are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11=11, 12

Count elements smaller than or equal to x in a sorted matrix in C++

Ravi Ranjan
Updated on 12-Jun-2025 17:19:15

254 Views

In this article, we are given a matrix of size m x n and an integer variable X. The row elements and the first column of the matrix are sorted in increasing order. Our task is to count the number of elements that are equal to or less than the given X value. Counting Elements Smaller Than X in a Sorted MatrixHere are the approaches for counting elements smaller than X in a sorted matrix: Using Linear Search Using Staircase Search Using Linear ... Read More

Count Number of animals in a zoo from given number of head and legs in C++

Sunidhi Bansal
Updated on 06-Jun-2020 12:04:31

1K+ Views

We are given a total number of heads and legs in a zoo and the task is to calculate the total number of animals there in the zoo with the given data. In the below program we are considering animals to be deer and peacocks.Input −heads = 60 legs = 200Output −Count of deers are: 40 Count of peacocks are: 20Explanation −let total number of deers to be : x Let total number of peacocks to be : y As head can be only one so first equation will be : x + y = 60 And deers have 4 ... Read More

Count frequency of k in a matrix of size n where matrix(i, j) = i+j in C++

Sunidhi Bansal
Updated on 06-Jun-2020 12:00:30

294 Views

We are given a matrix of integer values and the task is to calculate the count of the frequency of a given integer variable let’s say, k in the matrix. The size of a matrix can depend upon the size the user wants and in the below program we are taking it to be 4X4. Matrix will be formed on the given condition i.e matrix(i, j) will be i+j. The index value of the first data in a matrix will be 0 and 0 i.e. matrix[0][0] = 0.Input − int size = 4, k = 4Output − count of 4 ... Read More

Count n digit numbers not having a particular digit in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:56:53

275 Views

We are given a number let’s say, num and a total number of digits stored in an integer type variable let’s say, digi and the task is to calculate the count of those n digits numbers that can be formed where the given digit is not there.Input − n = 2, digit = 2Output − count is 153Explanation − count of all two digit numbers(n) not having digit 2 is 153 as 10, 11, 13, 14, 15, 16, 17, 18, 19, 30, 31, 33, 34, ......., etc.Input − n = 3, digit = 3Output − count is 2187Explanation − count ... Read More

Count digits in given number N which divide N in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:53:47

2K+ Views

We are given a number let’s say, N and the task is to find the count of those digits in a number that divides the number N.Points to be rememberIf the digit is 0 then it should be ignored which means count will not be increased for 0.If a digit is appearing twice and it divides the number, then the count will depend upon the digit occurrence. For example, we are given a number 2240 and in this number every digit except the 0 will divide the number and 2 is occurring twice then the count will be 2 for ... Read More

Count n digit numbers divisible by given number in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:51:27

412 Views

We are given the two elements let’s say, d and num, the task is to find the d digit numbers which are divisible by num.In simple words let us suppose we have given an input 2 in d, so we will first find all the 2-digit numbers i.e. from 10-99 and then find all the numbers which are divisible by num.Let us understand more of this with the help of examples −Input − digit = 2, num= 12Output − Count of n digit numbers divisible by given number: 8Explanation − The 2-digit numbers divisible by 12 are 12, 24, 36, ... Read More

Count entries equal to x in a special matrix in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:49:25

366 Views

Given a square matrix, mat[][] let the elements of the matrix me mat[i][j] = i*j, the task is to count the number of elements in the matrix is equal to x.Matrix is like a 2d array in which numbers or elements are represented as rows and columns.So, let's understand the solution of the problem with the help of examples −Input −matrix[row][col] = {    {1, 2, 3},    {3, 4, 3},    {3, 4, 5}}; x = 3Output −Count of entries equal to x in a special matrix: 4Input −matrix[row][col] = {    {10, 20, 30},    {30, 40, 30}, ... Read More

Maximum area of rectangle possible with given perimeter in C++

Sunidhi Bansal
Updated on 06-Jun-2020 11:44:04

395 Views

Given a perimeter of a rectangle, the task is to find the maximum area of the rectangle with that given perimeter.A rectangle is a type of parallelogram whose opposite sides are equal and parallel.The perimeter of a rectangle is the sum of all sides of a rectangle; we can also say perimeter is the total distance of the outside of the rectangle.The formula to find the perimeter of a rectangle is − Length + Breadth + Length + Breadth or 2(Length + Breadth)Whereas the area of a rectangle is the size of the rectangular object. The formula for finding the ... Read More

Advertisements