小数点后的数字 [英] Digits after the decimal point
问题描述
我正在从事计算机科学的工程学(B.Tech)。
我有一个问题,我正在努力编写C代码(程序)。
当我们被教导一个计算给定数字中
位数的程序时,这让我很震惊。
我请求帮我解决下面提到的问题。
要求用户输入小数/浮点数(例如32.8952),然后计算
该数字的位数小数点后(这个
的情况下为4)。
例如:如果用户输入45.99420,那么我们应该得到5,这是数字
$ b $小数点后的数字。
- Kuljit
I am doing Engineering(B.Tech) in Computer Science.
I have a question for which i am struggling to write a C code(program).
It struck me when we were being taught about a program which counts the
number of digits in a given number.
I request to help me out in solving the below said question.
Ask the user to enter a decimal/float number(eg. 32.8952), then count
the number of digits in that number after the decimal point(4 in this
case).
eg: If user enters 45.99420 then we should get 5, which are the number
of digits after the decimal point.
- Kuljit
推荐答案
Kuljit写道:
Kuljit wrote:
我在做计算机科学的工程学(B.Tech)。
我有一个问题,我正在努力写一个C代码(程序)。
当我们被教导时,它让我印象深刻回合一个计算给定数字中数字位数的程序。
我请求帮助我解决下面提到的问题。
要求用户输入一个小数/浮点数(例如32.8952),然后计算小数点后该数字的位数(在这个案例中为4)。
例如:如果用户输入45.99420那么我们应该得到5 ,这是小数点后数字的数字。
- Kuljit
I am doing Engineering(B.Tech) in Computer Science.
I have a question for which i am struggling to write a C code(program).
It struck me when we were being taught about a program which counts the
number of digits in a given number.
I request to help me out in solving the below said question.
Ask the user to enter a decimal/float number(eg. 32.8952), then count
the number of digits in that number after the decimal point(4 in this
case).
eg: If user enters 45.99420 then we should get 5, which are the number
of digits after the decimal point.
- Kuljit
嗯......
我会告诉你这样做的算法,你做代码:)
1.分配一个缓冲区来保存输入为字符串(例如char输入[80])
2.使用scanf(提示:scanf("%s",输入))
3.开始逐个字符串(假定ASCII)
4.当你遇到char x =''。''开始增加一个计数器
5.当你到达''\0''时完成递增/>
希望你能自己编写代码。
Well...
I''ll tell you the algorithm for doing it, you do the code :)
1. Allocate a buffer to hold the input as a string(eg char input[80])
2. Use scanf(hint: scanf("%s", input))
3. Start walking the string character by character(assumes ASCII)
4. When you encounter the char x = ''.'' start increment a counter
5. Finish incrementing when you''ve reached ''\0''
Hope you can write the code yourself.
" Kuljit"写道:
"Kuljit" writes:
我正在做计算机科学的工程学(B.Tech)。
我有一个问题,我正在努力编写C代码(程序)。
当我们被教导一个计算给定数字中数字位数的程序时,这让我感到震惊。
我请求帮助我解决下面提到的问题。
要求用户输入小数/浮点数(例如32.8952),然后计算小数点后该数字的位数(本案例中为4) )。
例如:如果用户输入45.99420,那么我们应该得到5,这是小数点后数字的数字。
I am doing Engineering(B.Tech) in Computer Science.
I have a question for which i am struggling to write a C code(program).
It struck me when we were being taught about a program which counts the
number of digits in a given number.
I request to help me out in solving the below said question.
Ask the user to enter a decimal/float number(eg. 32.8952), then count
the number of digits in that number after the decimal point(4 in this
case).
eg: If user enters 45.99420 then we should get 5, which are the number
of digits after the decimal point.
将输入读入字符串。 getline()可能是一个不错的选择。
搜索小数点然后计算数字直到你到达结尾
的数字。请注意,您可以使用
s [i]查看字符串s中的字符,非常类似于数组。
Read the input into a string. getline() would probably be a good choice.
Search for the decimal point and then count digits until you get to the end
of the number. Note that you can look at a character in a string, s, with
s[i], much like an array.
" osmium" ;写道:
< snip>
没关系。错误的消息。
"osmium" writes:
<snip>
Never mind. Wrong news froup.
这篇关于小数点后的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!