Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PISMENI ISPIT - 26.1.2018. (A)
- //1. zadatak --------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int i, j, m, n;
- float max, zbroj = 0;
- float polje[18][20];
- do {
- printf("Unesite m: ");
- scanf("%d", &m);
- } while (m < 10 || m >= 19);
- do {
- printf("Unesite n: ");
- scanf("%d", &n);
- } while (n < 11 || n > 20);
- srand((unsigned)time(NULL));
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- {
- polje[i][j] = -10 + (float)rand() / RAND_MAX * (10 + 20); //a[i] = DG + (float)rand() / RAND_MAX * (GG - DG);
- }
- }
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- printf("%.2f\t", polje[i][j]);
- printf("\n");
- }
- max = polje[0][0];
- for (j = 0; j < n; j++)
- {
- for (i = 0; i < m; i++)
- {
- if (polje[i][j] > max)
- max = polje[i][j];
- }
- zbroj += max;
- }
- printf("%.2f\n", zbroj);
- return 0;
- }
- //2. zadatak --------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int faktorijel (int n)
- {
- int f = 1, i;
- int digit, sum = 0;
- if(n < 0)
- {
- return -1;
- }
- for (i = 2; i <= n; i++)
- {
- f *= i;
- }
- while(f > 0)
- {
- digit = f % 10;
- sum += digit;
- f = f / 10;
- }
- return sum;
- }
- int main ()
- {
- int a = 11, b;
- b = faktorijel(a);
- printf("%d", b);
- return 0;
- }
- //3. zadatak --------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int funkcija(long int polje[])
- {
- int i, digit, product = 1, posnum, pospro;
- int max = polje[0];
- for(i = 0; i < 204; i++)
- {
- if(polje[i] > max)
- {
- max = polje[i];
- posnum = i;
- }
- }
- while(polje[0] > 0)
- {
- digit = polje[i] % 10;
- product *= digit;
- polje[i] = polje[i] / 10;
- }
- int maxproduct = product;
- pospro = 0;
- for(i = 1; i < 204; i++)
- {
- while(polje[i] > 0)
- {
- digit = polje[i] % 10;
- product *= digit;
- polje[i] = polje[i] / 10;
- }
- if(product > maxproduct)
- {
- maxproduct = product;
- pospro = i;
- }
- }
- if(posnum == pospro)
- {
- return 1;
- }
- else
- return 0;
- }
- int main()
- {
- int i, n;
- long int *polje;
- polje = (long int *)malloc(204);
- srand((unsigned)time(NULL));
- for (i = 0; i < 204; i++)
- {
- polje[i] = -750 + (float)rand () / RAND_MAX * (1500);
- }
- n = funkcija(polje);
- printf("%d", n);
- return 0;
- }
- //4. zadatak --------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- float izracun(float *polje)
- {
- int i;
- float temp;
- for (i = 1; i < 9; i++)
- {
- temp = (float)pow(polje[i], -2) + 0.1;
- }
- return (1 - polje[0] + temp - polje[i + 1]);
- }
- int main()
- {
- int i;
- float *p, polje[10];
- srand((unsigned)time(NULL));
- for (i = 0; i < 10; i++)
- {
- polje[i] = -5.12 + (float)rand() / RAND_MAX * 10.24;
- }
- p = polje;
- printf("%.2f\n", izracun(p));
- return 0;
- }
- //5. zadatak --------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void toupper(char *string)
- {
- int i;
- for (i = 0; i < '/0'; i++)
- {
- if (string[i] >= 'a' && string[i] <= 'z')
- {
- string[i] = string[i] - 'a' + 'A';
- }
- }
- printf("%s", string);
- }
- int main(void)
- {
- char *string;
- string = (char *)malloc(200);
- printf("Unesite zeljeni string:");
- fgets(string, 200, stdin);
- toupper(string);
- free(string);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement