Subversion Repositories svnkaklik

Rev

Rev 263 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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