Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void popuni(int *c, int dg, int gg)
- {
- for (int i = 0; i < 5; i++)
- {
- c[i] = (int) dg + (float)rand() / RAND_MAX * (gg - dg);
- printf("[%d] = %d\n", i, c[i]);
- }
- }
- int main(void)
- {
- //1.
- float a[1000], zbr = 0;
- int i, n = 0;
- srand((unsigned)time(NULL));
- for (i = 0; i < 1000; i++)
- {
- n++;
- a[i] = (float)rand() / RAND_MAX * 10;
- zbr += a[i];
- }
- printf("Srednja vrijednost je: %f\n", zbr/n);
- //2.
- float b[20][20], dg = -5, gg = 5, nm = 5, nv = -5;
- srand((unsigned)time(NULL));
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 20; j++)
- {
- b[i][j] = dg + (float)rand() / RAND_MAX * (gg - dg);
- if (nv < b[i][j])
- nv = b[i][j];
- if (nm > b[i][j])
- nm = b[i][j];
- }
- }
- printf("Najveca vrijenost je : %f, a najmanja %f/n", nv, nm);
- //3.
- int dG, gG, c[5];
- printf("\nUnesite donju granicu");
- scanf("%d", &dG);
- printf("\nUnesite gornju granicu");
- scanf("%d", &gG);
- printf("Generirani brojevi unutar granica [%d, %d] su:\n", dG, gG);
- popuni(c, dG, gG);
- //4
- int d[150];
- float temp;
- printf("Vrijednosti polja su:\n");
- for (int i = 0; i < 150; i++)
- {
- temp = (float)rand() / RAND_MAX * 1;
- if (temp < 0.5)
- d[i] = 0;
- else d[i] = 1;
- printf("%d", d[i]);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement