Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

C++ program to find number of integers which has exactly x divisors

Number of integers which has exactly x divisors

 
            Numbers dividing with self or 1 are called prime numbers but numbers having multiple divisors are called composite numbers. In this c++ program, we will find the numbers with the exact number of divisors defined by the user. The divisor of a number is defined as, when we divide a number ‘a’ by other number ‘b’ and gives remainder zero, so the ‘b’ will be considered as the divisor of the ‘a’. We will find the number of the divisor of the numbers and print them along with the count of numbers.
count-of-x-divisors

Algorithm

  • Take user inputs like Number and Divisors.
  • Initialize a count variable with zero value.
  • Run a for loop with a range from 1 to Number+1.
  • Initialize another count variable with zero.
  •  Run other for loop ranging from 1 to iterator of 1st for loop+1.
  •  Check for complete division conditions and if TRUE increment count2 by 1.
  •  Come out of for loop and check if count2 is equal to Divisor.
  •  If TRUE increment count1 by 1 and print the number with exact divisors.
  • Print count1.

C++ Code:-

    
    //C++ program
    //Strong Number or not
    #include<iostream>
    using namespace std;
    //main Program
    int main()
    {
        int Number,Divisor,count1;
        cout<<\nEnter range of number :”;
        cin>>Number;
        cout<<\nEnter exact number of divisors :”;
        cin>>Divisor;
        //count1 is to count total number of Numbers with exact divisor
        count1 = 0;
        for(int i=0;i<=Number;i++)
        {
            //count2 checks the total number of divisors
            int count2 = 0
            //loop to find number of divisors
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    count2++;
                }
            }
            if(count2==Divisor)
            {
                count1++;
                cout<<i<<” “;
            }
            
        }
        cout<<\n<<count1;
    }


    
    Output:
    Enter range of number :30
    Enter exact number of divisors :3
    4 9 25
    3
coding (3)
  • Highest Common Factor(HCF): C | C++Java | Python
  • Lowest Common Multiple (LCM) : C | C++ | Java | Python
  • Greatest Common Divisor : C | C++ | Java | Python
  • Binary to Decimal to conversion : C | C++ | Java | Python
  • Binary to Octal conversion : C | C++ | Java  | Python
  • Decimal to Binary conversion: C | C++ | Java | Python
  • Decimal to octal Conversion: C | C++ | Java | Python
  • Octal to Binary conversion : C | C++ | Java | Python
  • Octal to Decimal conversion : C | C++ | Java | Python
  • Quadrants in which a given coordinate lies : C | C++ | Java | Python
  • Permutations in which n people can occupy r seats in a classroom : C | C++ | Java | Python
  • Maximum number of handshakes: C | C++ | Java | Python
  • Addition of two fractions: C | C++ | Java | Python
  • Replace all 0’s with 1 in a given integer : C | C++ | Java | Python
  • Can a number be expressed as a sum of two prime numbers : C | C++ | Java | Python
  • Count possible decoding of a given digit sequence : C | C++ | Java
  • Check whether a character is a vowel or consonant : C | C++ | Java | Python
  • Check whether a character is a alphabet or not : C | C++ | Java | Python
  • Calculate the area of a circle : C | C++ | Java | Python
  • Find the ASCII value of a character : C | C++ | Java | Python
  • Find the prime numbers between 1 to 100 : C | C++ | Java | Python
  • Calculate the number of digits in an integer : C | C++ | Java | Python
  • Convert digit/number to words : C | C++ | Java | Python
  • Counting number of days in a given month of a year: C | C++ | Java | Python
  • Finding Number of times x digit occurs in a given input : C | C++ | Java | Python
  • Finding number of integers which has exactly x divisors: C | C++ | Java | Python
  • Finding Roots of a quadratic equation : C | C++ | Java | Python