**The Program in C++ to Check If Given Number is an Ugly number or not** **is given below:**

```
#include <iostream>
// Function to check if a number is an ugly number
bool isUgly(int num) {
if (num <= 0) return false;
if (num == 1) return true;
while (num % 2 == 0) num /= 2;
while (num % 3 == 0) num /= 3;
while (num % 5 == 0) num /= 5;
return num == 1;
}
int main() {
int num;
std::cout << "Hello Codeauri Family, enter a number here to know if it is ugly number or not!: ";
std::cin >> num;
// Check if the number is an ugly number
if (isUgly(num)) {
std::cout << num << " is an ugly number." << std::endl;
} else {
std::cout << num << " is not an ugly number." << std::endl;
}
return 0;
}
```

## Output:

Hello Codeauri Family, enter a number here to know if it is ugly number or not!: 15

15 is an ugly number.

## Pro-Tips💡

An ugly number is a number whose only prime factors are 2, 3, and 5.

The `isUgly`

function takes a number as input and returns `true`

if it is an ugly number, and `false`

otherwise.

The function checks if the number is less than or equal to 0 or equal to 1, and returns the corresponding value.

If the number is not 1 or less than or equal to 0, the function divides the number by 2, 3, and 5 as many times as possible, and returns `true`

if the resulting number is 1 and `false`

otherwise.

**Learn C-Sharp ↗**

C-sharp covers every topic to learn about C-Sharp thoroughly.

**Learn C Programming ↗**

C-Programming covers every topic to learn about C-Sharp thoroughly.

**Learn C++ Programming↗**

**Learn C++ Programming↗**

C++ covers every topic to learn about C-Sharp thoroughly.