Fascinating Number Program in C2 min read

In this tutorial, we will write a C program to check whether the given number is a Fascinating number or not. You may go through the following topics first in C.

What is Fascinating Number?

A number is said to be a fascinating number if it is (having at least 3 digits) multiplied by 2 and 3, and then both these product’s results are concatenated with the original number, then the new number contains all the digits from 1 to 9 exactly once. There could be any number of zeros and are ignored.

Fascinating number example:

Consider a Number = 192
Then multiply it by two and 3
192 × 2 = 384
192 × 3 = 576
Concatenating the above two numbers with the original number, we get:
“192” + “384” + “576” = 192384576 = result.
Now the final result contains all the digits from 1 to 9. Hence it is a Fascinating Number.


Procedure for Fascinating Number

  1. First, check if the entered/given number has three digits or not. If not, print “cannot be a Fascinating Number”.
  2. Else, Multiply the given number with 2 and 3.
  3. Then convert the product result into a string and Concatenate those strings along with the original number.
  4. Iterate the string that we get after concatenation and also keep the frequency count of the digits.
  5. Print “Not a Fascinating Number” if any of the digits (1 to 9) is missing or repeated.
  6. Else, print “It is a Fascinating Number”.

C Program for Fascinating Number

Output:

Enter a number: 192
192 is a Fascinating number.


MORE

Find a pair with the Given Sum in an Array in Java

In this tutorial, we will write a java program to find the sum pair in an array. Before that, you may go through the following …
Read More

C++ Program to display Pascal Triangle

In this tutorial, we will write a C++ program to display pascal’s triangle. Before that, you may go through the following topic in C++. for …
Read More

C++ Program to Calculate Sum of Geometric Progression

In this tutorial, we will learn and write a program to find the sum of GP series in C++. Before that, you may go through …
Read More

C++ Program to find the Transpose of a Matrix

In this tutorial, we will learn and write a program to find the transpose of matric in C++. Before that, you may go through the …
Read More

How to Split a String in C++

Let us learn how to split string in C++ programming language. We will look at a few ways to split a string. The splitting of …
Read More

C++ Program to calculate Average of Numbers using Arrays

In this tutorial, we will learn and write a C++ program to find the average of numbers using an array. To understand the coding, you …
Read More