473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can i count the digits of number given by the user

1 New Member
how can i count the digits of number given by the user
Nov 22 '07 #1
8 4093
Meetee
931 Recognized Expert Moderator Contributor
how can i count the digits of number given by the user
You can take the value in string and can count by counting each char of that string until the end of the string. Search google for more. And if doubt, paste your efforts in the next post.

Regards
Nov 22 '07 #2
mohammadazim
28 New Member
You can take the value in string and can count by counting each char of that string until the end of the string. Search google for more. And if doubt, paste your efforts in the next post.

Regards
Above solution is good. But if you some computing you can do as following pseudo code
Expand|Select|Wrap|Line Numbers
  1. number = user input
  2. numberDigits = 1
  3. place = 10
  4. while number >= place
  5. {
  6. numberDigits++
  7. place *= 10
  8. }
  9.  
output number
Nov 22 '07 #3
mailavi
13 New Member
Above solution is good. But if you some computing you can do as following pseudo code

number = user input
numberDigits = 1
place = 10
while number >= place
{
numberDigits++
place *= 10
}

output number

there is another way....... first u take the number from the user into a variable then divide the number with 10 u would get the unit's place digit the so on to get the individual number and add them........
Nov 29 '07 #4
MarshMallow
52 New Member
Ciao Bettina,
please prompt, the user for a string ,not an integer;and then take a look to the ANSI C header <string.h> ,there is the function strlen wich counts the number of characters in a string,that could be useful!
Nov 29 '07 #5
oler1s
671 Recognized Expert Contributor
Simpler method:

Take input into a string. Convert that string into a number. Then number of digits is log(number)+1.
Nov 29 '07 #6
Ganon11
3,652 Recognized Expert Specialist
Simpler method:

Take input into a string. Convert that string into a number. Then number of digits is log(number)+1.
Just to clarify, this is log with base 10. I'm not sure if the log function in cmath evaluates log base 10, log base 2, or natural log (log base e). To make sure, use log(number)/log(desired base). No matter what base the log function is, dividing by log(desired base) results in the same answer as a log to the correct base of number.
Nov 29 '07 #7
oler1s
671 Recognized Expert Contributor
There's a both a log (natural log) and log10 (base 10 log) function in the math library.
Nov 29 '07 #8
MarshMallow
52 New Member
according to compilers,there can be different implementation of the logarithm function;but basically log is computed dividing the input iteratively by ten,checking if it is >0 and incrementing a counter;we know that a microprocessor performs division through a series of right shifts;so computing the logarithm consist basically of shifting,compar ing and incrementing registers;strle n only perfrom a comparison and increment a counter,without stressing ALU with shifts;though strlen algorithm has linear complexity,so it is not a big advantage to use it when the string is "long"
Nov 29 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6489
by: mark | last post by:
How to extract digits from a given number say double number is 10.9876 extract two digits after decimal - 98 extract three digits after decimal - 987 and represent the extracted number as an integer.
1
3876
by: Shreyas Kulkarni | last post by:
hi there, recently i have got a problem regarding calculation of sum of digits in a floating point or precision number. the weird behaviour of compiler/language is preventing me from calculating the sum of all digits. the compiler doesnt store the number as given by the user. some of the precision digits are lost or changed (at will!). so by any method, i m unable to reliably calculate the sum of provided number; except i input the...
27
31376
by: Luke Wu | last post by:
Is there a C function that returns the number of digits in an input int/long? example: numdigits(123) returns 3 numdigits(1232132) returns 7
68
6826
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
109
7630
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has 7 digits in base 10. Is there a way to compute that information without actually evaluating the factorial?
1
2768
by: psbasha | last post by:
Hi, How to find the number of digits from a given number?. For example num = 23456 The number of digits are 5 num = 2311150
2
3089
by: Smokey Grindle | last post by:
any fast way to do this? I just need to check if if a string which could have a lot of characters in it if it has numbers and count the number of numbers in the string. thanks!
4
2846
by: gaurav1983 | last post by:
i have to generate unique combinations of given number of digits entered by user eg: N=4 (0,1,2,3) output should be 0 1 2 3
1
3612
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent via an email function. But just can't figure it out. <? //////////////////////////////////////////////////////////// //
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.