Computer Science, asked by suryapratap85, 6 months ago

write a program to accept a natural number and display whether it is a one digit number or two digit number or three digit number or its contents four or more digit​

Answers

Answered by ıtʑFᴇᴇʟɓᴇãᴛ
34

\mathtt{\huge{\underline{\red{Programme:-}}}}

\mathtt{\bf{\underline{\pink{Python\:3:-}}}}

# Iterative Python program to count

# number of digits in a number

def countDigit(n):

count = 0

while n != 0:

n //= 5

count+= 1

return count

# Driver Code

n = 346284

print ("Number of digits : % d"%(countDigit(n)))

\mathtt{\huge{\underline{\green{Output:-}}}}

➝ Number of digit = 4

____________________________________

For more than 4 :-

\mathtt{\huge{\underline{\red{Programme:-}}}}

# Iterative Python program to count

# number of digits in a number

def countDigit(n):

count = 0

while n != 0:

n //= 4+n , (n= 1,2,3,4......,n )

count+= 1

return count

# Driver Code

n = 34628456555n

print ("Number of digits : % d"%(countDigit(n)))

\mathtt{\huge{\underline{\green{Output:-}}}}

➝ Number of digit = 4+n , (n= 1,2,3,4......,n )

_________________________________

Answered by anindyaadhikari13
5

Question:-

Write a program to accept a natural number and display whether it is a one digit number or two digit number or three digit number or its contents four or more digit.

Code:-

In Java....

class Number

{

public static void main(int n)

{

int c=0;

for(;n!=0;n/=10)

c++;

System.out.println("Number of digits: "+c);

}

}

ln Python...

n=int(input("Enter a number: "))

c=0

while n!=0:

c=c+1

n=n/10

print("Total number of digits: ",c)

Similar questions