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
Refactorable number in C++
We are given an integer type value, let's say, number. The task is to check whether the given number is Refactorable or not. If yes print that the number is a refactorable number else print not possible.
What is a Refactorable Number?
A number is refactorable when it is divisible by its total count of factors available. For example, number 9 is refactorable as it has a total number of factors i.e. 3(1, 3, 9) and 9 is divisible by 3 hence its a refactorable number.
Let us see various input output scenarios for this −
Input − int number = 9
Output − It is a Refactorable number
Explanation − A number is refactorable when it is divisible by its total count of factors available. We are given a number 9, which is refactorable as it has a total number of factors i.e. 3(1, 3, 9) and 9 is divisible by 3 hence its a refactorable number.
Input − int number = 10
Output − It isn't a Refactorable number
Explanation − A number is refactorable when it is divisible by its total count of factors available. We are given a number 10, which isn't refactorable as it has a total number of factors i.e. 4(1, 2, 5, 10) and 10 isn’t divisible by 4 hence it is not a refactorable number
Approach used in the below program is as follows
Input a variable of integer type, let’s say, number.
Pass the data to the function check_Refactorable(int number) of the bool type.
-
Inside the function check_Refactorable(int number)
Declare an integer type variable as count to 0.
Start loop FOR from i to 1 till i is less than sqrt(number). Inside the loop, check IF number % i = 0 then check IF number / i = i then pre increment the count by 1.
ELSE, set the count as count + 2.
Return number % count == 0
Print the result.
Example
#includeusing namespace std; bool check_Refactorable(int number){ int count = 0; for (int i = 1; i Output
If we run the above code it will generate the following Output
It is a Refactorable number
