Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <random>
- using namespace std;
- template <typename dataType>
- static dataType RNG(dataType from, dataType to)
- {
- random_device rd; // better source of seeds than time()
- mt19937 gen(rd()); // seed Mersenne Twister
- uniform_int_distribution<> rand(from, to); // range of numbers
- return rand(gen);
- }
- int main(void)
- {
- //printf("//==================\\ ZADATAK [1] //==================\\\n");
- //int *a, br, nm = 100, nv = -100;
- //printf("Unesize zeljenu velicinu polja: ");
- //scanf("%d", &br);
- //a = (int *)malloc(br*sizeof(int));
- //if (a == NULL)
- // return 1;
- //for (size_t i = 0; i < br; i++)
- //{
- // a[i] = RNG<int>(-100, 100);
- // if (a[i] < nm)
- // nm = a[i];
- // if (a[i] > nv)
- // nv = a[i];
- //}
- //printf("najveci je %d, a najmanji %d\n\n", nv, nm);
- //free(a);
- //printf("//====================================================\\\n");
- //printf("\n//==================\\ ZADATAK [2] //==================\\\n");
- //double *b;
- //int rand = RNG(50, 100);
- //
- //b = (double *)malloc(br*sizeof(double));
- //if (b == NULL)
- // return 1;
- //for (size_t i = 0; i < rand; i++)
- //{
- // double c= 0.0, d = 1.0;
- // b[i] = RNG<double>(c,d);
- // if (b[i] == 1)
- // printf("b[%d] == 1 \n", i);
- //}
- //free(b);
- //printf("//====================================================\\\n");
- printf("\n//==================\\ ZADATAK [3] //==================\\\n");
- int length = 0, space = 0;
- char *str;
- while (length > 1 && length < 500);
- {
- printf("Unesite zeljenu duljinu stringa ");
- scanf_s("%d", &length);
- }
- fseek(stdin, 0, SEEK_END);
- str = (char *)malloc((length)*sizeof(char));
- if (str == NULL)
- return NULL;
- printf_s("\nUnesite %d, znakova u string: ", length);
- do{
- fgets(str, length, stdin);
- } while (strlen(str) <= 1 && strlen(str) >= length);
- for (size_t i = 0; i < strlen(str); i++)
- {
- if (str[i] ==' ')
- space++;
- }
- printf("\Broj razmaka iznosi: %d ", space);
- free(str);
- printf("//====================================================\\\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement