Advertisement
eniodordan

PISMENI ISPIT - 26.1.2018. (A)

Jun 15th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.22 KB | None | 0 0
  1. //PISMENI ISPIT - 26.1.2018. (A)
  2.  
  3. //1. zadatak --------------------------------------------------------------------------------------------------------------------------
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7.  
  8. int main()
  9. {
  10.     int i, j, m, n;
  11.     float max, zbroj = 0;
  12.     float polje[18][20];
  13.  
  14.     do {
  15.         printf("Unesite m: ");
  16.         scanf("%d", &m);
  17.     } while (m < 10 || m >= 19);
  18.  
  19.     do {
  20.         printf("Unesite n: ");
  21.         scanf("%d", &n);
  22.     } while (n < 11 || n > 20);
  23.  
  24.     srand((unsigned)time(NULL));
  25.  
  26.     for (i = 0; i < m; i++)
  27.     {
  28.         for (j = 0; j < n; j++)
  29.         {
  30.             polje[i][j] = -10 + (float)rand() / RAND_MAX * (10 + 20); //a[i] = DG + (float)rand() / RAND_MAX * (GG - DG);
  31.         }
  32.     }
  33.  
  34.     for (i = 0; i < m; i++)
  35.     {
  36.         for (j = 0; j < n; j++)
  37.             printf("%.2f\t", polje[i][j]);
  38.         printf("\n");
  39.     }
  40.  
  41.     max = polje[0][0];
  42.  
  43.     for (j = 0; j < n; j++)
  44.     {
  45.         for (i = 0; i < m; i++)
  46.         {
  47.             if (polje[i][j] > max)
  48.                 max = polje[i][j];
  49.         }
  50.  
  51.         zbroj += max;
  52.     }
  53.  
  54.     printf("%.2f\n", zbroj);
  55.  
  56.     return 0;
  57. }
  58.  
  59. //2. zadatak --------------------------------------------------------------------------------------------------------------------------
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62. #include <time.h>
  63.  
  64. int faktorijel (int n)
  65. {
  66.     int f = 1, i;
  67.     int digit, sum = 0;
  68.    
  69.     if(n < 0)
  70.     {
  71.         return -1;
  72.     }
  73.    
  74.     for (i = 2; i <= n; i++)
  75.     {
  76.         f *= i;
  77.     }
  78.    
  79.     while(f > 0)
  80.     {
  81.         digit = f % 10;
  82.         sum += digit;
  83.         f = f / 10;
  84.     }
  85.    
  86.     return sum;
  87. }
  88.  
  89. int main ()
  90. {
  91.     int a = 11, b;
  92.    
  93.     b = faktorijel(a);
  94.     printf("%d", b);
  95.    
  96.     return 0;
  97. }
  98.  
  99. //3. zadatak --------------------------------------------------------------------------------------------------------------------------
  100. #include <stdio.h>
  101. #include <stdlib.h>
  102. #include <time.h>
  103.  
  104. int funkcija(long int polje[])
  105. {
  106.     int i, digit, product = 1, posnum, pospro;
  107.    
  108.     int max = polje[0];
  109.     for(i = 0; i < 204; i++)
  110.     {
  111.         if(polje[i] > max)
  112.         {
  113.             max = polje[i];
  114.             posnum = i;
  115.         }
  116.     }
  117.    
  118.     while(polje[0] > 0)
  119.     {
  120.         digit = polje[i] % 10;
  121.         product *= digit;
  122.         polje[i] = polje[i] / 10;
  123.     }
  124.     int maxproduct = product;
  125.     pospro = 0;
  126.    
  127.     for(i = 1; i < 204; i++)
  128.     {
  129.         while(polje[i] > 0)
  130.         {
  131.             digit = polje[i] % 10;
  132.             product *= digit;
  133.             polje[i] = polje[i] / 10;
  134.         }
  135.            
  136.         if(product > maxproduct)
  137.         {
  138.             maxproduct = product;
  139.             pospro = i;
  140.         }
  141.     }
  142.    
  143.     if(posnum == pospro)
  144.     {
  145.         return 1;
  146.     }
  147.     else
  148.         return 0;
  149. }
  150.  
  151. int main()
  152. {
  153.     int i, n;
  154.     long int *polje;
  155.    
  156.     polje = (long int *)malloc(204);
  157.    
  158.     srand((unsigned)time(NULL));
  159.    
  160.     for (i = 0; i < 204; i++)
  161.     {
  162.         polje[i] = -750 + (float)rand () / RAND_MAX * (1500);
  163.     }
  164.    
  165.     n = funkcija(polje);
  166.     printf("%d", n);
  167.    
  168.     return 0;
  169. }
  170.  
  171. //4. zadatak --------------------------------------------------------------------------------------------------------------------------
  172. #include <stdio.h>
  173. #include <stdlib.h>
  174. #include <time.h>
  175. #include <math.h>
  176.  
  177. float izracun(float *polje)
  178. {
  179.     int i;
  180.     float temp;
  181.  
  182.     for (i = 1; i < 9; i++)
  183.     {
  184.         temp = (float)pow(polje[i], -2) + 0.1;
  185.     }
  186.  
  187.     return (1 - polje[0] + temp - polje[i + 1]);
  188. }
  189.  
  190. int main()
  191. {
  192.     int i;
  193.     float *p, polje[10];
  194.  
  195.     srand((unsigned)time(NULL));
  196.     for (i = 0; i < 10; i++)
  197.     {
  198.         polje[i] = -5.12 + (float)rand() / RAND_MAX * 10.24;
  199.     }
  200.    
  201.     p = polje;
  202.     printf("%.2f\n", izracun(p));
  203.  
  204.     return 0;
  205. }
  206.  
  207. //5. zadatak --------------------------------------------------------------------------------------------------------------------------
  208. #include <stdio.h>
  209. #include <stdlib.h>
  210. #include <time.h>
  211.  
  212. void toupper(char *string)
  213. {
  214.     int i;
  215.  
  216.     for (i = 0; i < '/0'; i++)
  217.     {
  218.         if (string[i] >= 'a' && string[i] <= 'z')
  219.         {
  220.             string[i] = string[i] - 'a' + 'A';
  221.         }
  222.     }
  223.  
  224.     printf("%s", string);
  225. }
  226.  
  227. int main(void)
  228. {
  229.     char *string;
  230.  
  231.     string = (char *)malloc(200);
  232.  
  233.     printf("Unesite zeljeni string:");
  234.     fgets(string, 200, stdin);
  235.  
  236.     toupper(string);
  237.     free(string);
  238.  
  239.     return 0;
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement