当前位置: > c++ 硬币正反面问题...
题目
c++ 硬币正反面问题
Write a program that simulates coin tossing.For each toss of the coin the program should print Heads or Tails.Let the program toss the coin a number of times as specified by the user,and count the number of times each side of the coin appears.Print the results of each toss.The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads.Note:If the program realistically simulates the coin tossing,then each side of the coin should appear approximately half the time.
The program interaction should look as follows (user inputs are in bold):
Welcome to the Coin Tossing program.
Enter the number of tosses (-1 to exit):5
Flip 1 is a:HEAD
Flip 2 is a:TAIL
Flip 3 is a:HEAD
Flip 4 is a:HEAD
Flip 5 is a:TAIL
There were 3 heads and 2 tails in 5 tosses.
Enter the number of tosses (-1 to exit):-1
Thank you for using the Coin Flipping program and have a wonderful day.

提问时间:2021-04-01

答案
//用随机数函数来模拟硬币投掷即可,即rand() % 2即可以得到1或者0.
//VC6,xp系统
#include
#include
using namespace std;
int toss();
int main(void)
{
x05int head,tail,total,num,temp,cnt;
x05cout
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.