Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
263 kaklik 1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <time.h>
4
 
5
int rnd (int max)
6
{
7
  return ( (int) (max * (rand()/(RAND_MAX+1.0))));
8
}
9
 
10
void init_rnd(void)
11
{
12
  time_t t;
13
  unsigned int seed;
14
  time(&t);
15
  seed=(unsigned int) t;
16
  srand(seed);
17
}
18
 
19
int main()
20
{
21
 
22
int i=1,hledane,pokus;
23
 
24
  init_rnd();
25
 
26
  printf("program uhodne cislo od 0 do 100 \n ");
27
 
28
  hledane=rnd(10);
29
 
30
  do
31
  {
32
    printf("Pokus cislo %d   ",i);
33
	scanf("%d", &pokus);
34
	i++;
35
	if (pokus > hledane)  printf("Zadane cislo je vetsi nez hledane \n ");
36
	if (pokus < hledane)  printf("Zadane cislo je mensi nez hledane \n ");
37
	else  printf("Spravne cislo bylo nalezeno \n ");
38
  }
39
  while (pokus != hledane);
40
}