生成两个随机数并乘以 [英] Generate two random number and multiply

查看:63
本文介绍了生成两个随机数并乘以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新人,所以如果这是错误的,我道歉。我也是用C编程的新朋友,我一直在搜索如何使用C生成两个随机的
数字,

乘以它们,并询问结果。对于正确和错误的答案,它还需要有四个

响应,并且应该随机打印它们。该程序应至少使用2个功能。任何

帮助将不胜感激。


谢谢

I''m new so i apologize if this is in the wrong spot. I''m also new to
programming in C and i''ve been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks

推荐答案

jj**********@hotmail.com 写道:

我是新来的,所以如果这是在错误的地方,我道歉。我也是用C编程的新朋友,我一直在搜索如何使用C生成两个随机的
数字,

乘以它们,并询问结果。对于正确和错误的答案,它还需要有四个

响应,并且应该随机打印它们。该程序应至少使用2个功能。任何

帮助将不胜感激。


谢谢
I''m new so i apologize if this is in the wrong spot. I''m also new to
programming in C and i''ve been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks



这似乎是一个功课问题。你至少做了一次尝试。

尝试一下这个问题并在这里发布代码,无论多么糟糕

是。


提示:要生成伪随机整数值,请使用rand函数。

在使用它之前,建议调用srand函数

"种子"伪随机数发生器。要了解如何使用rand

和srand,请尝试查看

标准库的实现文档。如果它是Unix系统,请尝试在命令提示符下键入''man 3 rand''和

''man 3 srand''。


要从一个集合中随机选择一个字符串,你可以使用相同的

rand函数来获取一个随机数,将其调整到你的数组的

范围内字符串并使用它来索引数组和

提取一个随机字符串。


好​​吧,试试吧。

This seems like a homework question. Have you atleast made an attempt.
Attempt a try at the problem and post the code here, however bad it
is.

Hint: To generate pseudo-random integer values, use the rand function.
Before using it, it''s recommended to invoke the srand function to
"seed" the pseudo-random number generator. To learn how to use rand
and srand, try looking at your implementation''s documentation for the
Standard library. If it''s a Unix system, try typing ''man 3 rand'' and
''man 3 srand'' at the command prompt.

To select a string, from a collection randomly, you can use the same
rand function to get a random number, trim it down to be within the
bounds of your array of strings and use it to index into the array and
extract a random string.

Well, try your hand at it.


大约在2007年3月5日上午7:23, jj ********** @ hotmail.com 声明

以下内容:
At about the time of 3/5/2007 7:23 AM, jj**********@hotmail.com stated
the following:

I 我是新来的,如果这是在错误的地方,我道歉。我也是用C编程的新朋友,我一直在搜索如何使用C生成两个随机的
数字,

乘以它们,并询问结果。对于正确和错误的答案,它还需要有四个

响应,并且应该随机打印它们。该程序应至少使用2个功能。任何

帮助将不胜感激。


谢谢
I''m new so i apologize if this is in the wrong spot. I''m also new to
programming in C and i''ve been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks



家庭作业?


去看看和兰德(3)和srand(3)。这是标准C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


-

Daniel Rudy


电子邮件地址已经过base64编码以减少垃圾邮件

解码电子邮件地址使用b64decode或uudecode -m


为什么极客喜欢电脑:看看聊天日期触摸grep make unzip

strip view finger mount fcsk more fcsk yes spray umount sleep

Homework?

Go take a look and rand(3) and srand(3). It''s standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep




< jj ********** @ hotmail.comwrote in message

<jj**********@hotmail.comwrote in message

我是新的所以我道歉如果这是在错误的地方。我也是用C编程的新朋友,我一直在搜索如何使用C生成两个随机的
数字,

乘以它们,并询问结果。对于正确和错误的答案,它还需要有四个

响应,并且应该随机打印它们。该程序应至少使用2个功能。任何

帮助将不胜感激。
I''m new so i apologize if this is in the wrong spot. I''m also new to
programming in C and i''ve been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.



rand()将生成0到RAND_MAX之间的随机数。

RAND_MAX通常是32767,这对于算术训练而言太高了。


所以通过取模数100得到1 = 100范围内的随机数。有

更准确的方法,但现在应该没问题了。


不幸的是,你的程序会在每次运行时产生完全相同的数字。所以用时间()来调用srand()来播种随机数

生成器。


获得随机数后,用一个随机数打印出来消息要求

用户乘以。然后调用scanf()输入结果。别忘了

检查scanf()的返回值,以确保用户实际输入了一个

的数字。


现在您需要检查数字是否正确。如果是,再次调用

随机数生成器并打印出一个随机的做得好的消息 -

您可以使用开关 - 如果没有,打印出错误的答案消息。

-

免费游戏和编程好东西。
http://www.personal.leeds。 ac.uk/~bgy1mm

rand() will generate a random number between 0 and RAND_MAX.
RAND_MAX is usually 32767, which is too high for arithmetic drill.

So get a random number in the range 1 = 100 by taking modulus 100. There are
more accurate ways of doing this, but this should be fine now.

Unfortunately you program will generate exactly the same numbers on each
run. So call srand() with the time from time() to seed the random number
generator.

Having got your random numbers, print them out with a message asking the
user to multiply. Then call scanf() to input the result. Don''t forget to
check the return value of scanf() to make sure the user actually entered a
number.

Now you need to check whether the number is correct. If it is, call the
random number generator again and print out a random "well done" message -
you can use a switch - if not, print out a "wrong answer message".
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


这篇关于生成两个随机数并乘以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆