幼稚的c语言,分不是问题,只要有答案,如果做得非常好的话有大奖励!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:36:36
1 设计一个程序。随机的输入字母,统计被键入的字母直道程序产生下面的单词之一:at , is ,he ,we ,up 或on 当这些单词中的一个产生是,程序停止,并显示键入的字母总数。
(通过1到26之间的一个随机整数来选择一个字母)

2. Program new random functions,
(1) use rand() to write a function rand3() that can produce a random integer
between 1 and 3, that is, to produce a number from the set {1, 2, 3} with
equal probability.
(2) Assume you ONLY have function rand3() from previous exercise, please
write a function rand5() that can produce a random integer between 1 and
5, that is, to produce a number from the set {1, 2, 3, 4, 5} with equal
probability.
(3) Test rand5() 1,000,000 times to verify that each number in the set {1,
2, 3, 4, 5} indeed is produced with about equal frequency.

如需我翻译的话就说,应该可以看懂吧

请务必运行一下,在发给我之前,谢啦!!!!!!!!!

VC6.0上测试通过
两个写一起了.
VC 6.0测试通过

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
unsigned long rand5_count[5] = {0};

void Exe1()
{
unsigned long count;
char last;
char current;

printf ( "This is exercise 1:\n\n" );
current = rand()%26 + 'a';
count = 1;
while(1)
{
last = current;
current = rand()%26 + 'a';
printf ( "%c",current );
count++;
if ( last == 'a' && current == 't' )
break;
if ( last == 'i' && current == 's' )
break;
if ( last == 'h' && current == 'e' )
break;
if ( last == 'w' && current == 'e' )
break;
if ( last == 'u' && current == 'p' )
break;
if ( last == 'o' && current == 'n' )
break;