- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

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.

**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

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.

#include <bits/stdc++.h> using namespace std; bool check_Refactorable(int number){ int count = 0; for (int i = 1; i <= sqrt(number); ++i){ if(number % i==0){ if(number / i == i){ ++count; } else{ count += 2; } } } return number % count == 0; } int main(){ int number = 9; if(check_Refactorable(number) == 1){ cout<<"It is a Refactorable number"; } else{ cout<<"It isn't a Refactorable number"; } return 0; }

If we run the above code it will generate the following Output

It is a Refactorable number

- Related Questions & Answers
- Adam Number in C++
- Abundant Number in C ?
- Arithmetic Number in C++
- Ugly Number in C++
- Encode Number in C++
- Additive Number in C++
- Perfect Number in C++
- Woodall Number in C++
- Entringer Number in C++
- Eulerian Number in C++
- Kaprekar Number in C++
- Keith Number in C++
- Narayana number in C++
- Neon Number in C++
- Motzkin number in C++

Advertisements