Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Write a program to obtain a number (N) from the user and display whether the number is a one digit number, 2 digit number, 3 digit number or more than 3 digit number
###Input:
###Output: Print “1” if N is a 1 digit number.
Print “2” if N is a 2 digit number.
Print “3” if N is a 3 digit number.
Print “More than 3 digits” if N has more than 3 digits.
###Constraints
###Sample Input: 9
###Sample Output: 1
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String n = sc.next();
if(n.length() == 1)
System.out.println("1");
else if(n.length() == 2)
System.out.println("2");
else if(n.length() == 3)
System.out.println("3");
else
System.out.println("More than 3 digits");
}
}
n=int(input())
n=str(n)
if len(n)<3:
print(len(n))
elif len(n)==3:
print(len(n))
else:
print('More than 3 digits')
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,count=0; cin>>n;
while(n>0){
n/=10;
count++;
}
if(count<=3){
cout<<count<<endl;
}
else{
cout<<"More than 3 digits"<<endl;
}
return 0;
}
In our experience, we suggest you solve this HOW MANY DIGITS DO I HAVE CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the HOW MANY DIGITS DO I HAVE CodeChef Solution
I hope this HOW MANY DIGITS DO I HAVE CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>