+ 3
How can i know the number of numbers of a phone number in c langage
for example how can i know that 0666666666 is a 10 numbers number
9 Answers
+ 10
If the number is input as a string 'a', use strlen(a)
+ 8
In reference to @Ace's answer, you can always take input as string, check number of chars, and then 'convert' it to int for later operations.
+ 7
It's better to take huge values like Phone number as string because max value of int is 2,147,483,647.
Usually a phone number contains 10 digits plus a 2 digit country code. So, it is a better decision to input them as a string.
+ 6
int flag=0;
int num=63517381;
while (num>0)
{
flag++;
num/=10;
}
print (flag);//idk the syntax for output in C.
The output will be 8.
This is how to do it with Integer input.
However, I still recommend you use string input
+ 5
So in other words, how many digits there are in a number?
Use a while loop, and see how many times it takes to divide the number before it's less than one.
int numDigits = 0;
int num = 135;
while(num >= 1){
numDigits++;
num /= 10;
}
Or
If the number is a string (due to 0 in front), just get the string length.
+ 1
got it thank u all đ
0
but i have an integer, we can t get the lenght of an integer o.O .. didnt understand đ ..