Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
eg:
3 - 3 is the number of inputs user wants.It can be any input user wants.
19 - special number
11 - not a special number
5 - invalid number

Explanation:
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits
and product of digits = 14 + 45 = 59
so, 59 is a special number.

What I have tried:

Python
a = int(input())
b = 0
if a > 9:
    for i in range(a):
        c = int(input())
        while c > 0:
            d = b%10
            b+=0
            c//=10
        print(b)
else:
    print("Invalid number")
Posted
Updated 4-Sep-22 0:30am
v3
Comments
M Imran Ansari 21-Jan-22 9:53am    
Please elaborate you problem well and give more detail. How you will declare as Invalid or special number?
shri harshan 21-Jan-22 9:58am    
is it now ok sir?

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
too much code.

Some analysis will proof that, when using base 10, the two-digit number [ab] is a "special number" if and only if b is 9.

start with: 10*a + b = a + b + a*b
 
Share this answer
 
Python
print("Enter the number to be checked.")
num = int(input())
if num > 9:
    temp = num
    sum_of_digits = 0
    while temp > 0:
        digit = temp % 10
        temp = temp / 10
        sum_of_digits = sum_of_digits + digit
    temp = num
    products_of_digits = 1
    while temp > 0:
        digit = temp % 10
        temp = temp / 10
        products_of_digits = products_of_digits * digit
    if (sum_of_digits + products_of_digits) == num:
        print(str(num) + " is a Special Number.")
    else:
        print(str(num) + " is not a Special Number.")
else:
    print(str(num) + " is Invalid Number.")
 
Share this answer
 
v3
try
Python
iterations = int(input())
  
for i in range (iterations):
  n = int(input())
  if n < 10 :
    print("invalid number")
  else:
    m = n
    s = 0
    p = 1
    while m>0:
      digit = m % 10
      s = s + digit
      p = p * digit
      m = m // 10
    if p + s == n:
      print("special number")
    else:
      print("ordinary number")
 
Share this answer
 
#Write a program to find all special numbers between 2 limits m and n(both inclusive).
res=0
for i in range(11,30):
n=i
temp=n
res=0
while(n>0):
rem=n%10
res=rem+res+res*rem
n=n//10
if(res==temp):
print(res)
 
Share this answer
 
# To Check Whether A Number Is A Special Number Or Not.

n = int(input("Enter the number to be checked: "))
if n > 9:
    t = n
    sum = 0
    while t > 0:
        d = t % 10
        t = t // 10
        sum = sum + d
    t = n
    product = 1
    while t > 0:
        d = t % 10
        t = t // 10
        product = product * d
    if (sum + product) == n:
        print("The No. is a Special Number.")
    else:
        print("The No. is not a Special Number.")
else:
    print("The No. is Invalid Number.")
 
Share this answer
 
Comments
CHill60 4-Sep-22 11:23am    
This is no different to solution 2. Copying work is plagiarism and is not tolerated here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900