Advertisement
MilanR

C za djuru

Jan 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. //1. Zadatak
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int main(int argc, char const *argv[])
  6. {
  7.     double y;
  8.     for (int x = -4; x <= 4; x++) {
  9.         if ( x < 0) {
  10.             y = pow(x, 3) + pow(2, x);
  11.         } else if ( x <= 1) {
  12.             y = sin(pow(x, 3))+ cos(x);
  13.         }
  14.         else {
  15.             y = sqrt(sin(3*x));
  16.         }
  17.         printf("Za vrednost argumenta x = %d funkcija ima vrednost y = %f\n", x, y);
  18.     }
  19.     return 0;
  20. }
  21.  
  22. //2. Zadatak
  23. #include <stdio.h>
  24.  
  25. double povrsina(int r) {
  26.     return 4* 3.14 * r *r;
  27. }
  28.  
  29. double zapremina(int r) {
  30.     return 4/3 * 3.14 * r*r*r;
  31. }
  32. int main()
  33. {
  34.     double s = 0;
  35.     int n;
  36.     scanf("%d", &n);
  37.    
  38.     for (int i = 0; i < n; i++) {
  39.         printf("Unesite podatke za %d. loptu\n", i+1);
  40.        
  41.         int r;
  42.         scanf("%d", &r);
  43.         s += povrsina(r);
  44.         printf("Lopta broj %d sa poluprecnikom %d ima zapreminu %0.2f\n", i+1, r, zapremina(r));
  45.     }
  46.     printf("Ukupna pov lopti je %f\n", s);
  47.     return 0;
  48. }
  49.  
  50. //3. Zadatak
  51. #include <stdio.h>
  52. #include <time.h>
  53. #include <stdlib.h>
  54.  
  55. int main()
  56. {
  57.     srand(time(NULL));
  58.  
  59.     int a1[20], a2[20], a3[20];
  60.     int n1 = 0, n2 = 0, n3 = 0;
  61.  
  62.     int count = 1;
  63.     int br = rand() % 10001;
  64.     while (br != 100 && count < 20) {
  65.         count ++;
  66.  
  67.         cJedinica = br % 10;
  68.         cDesetica = (br / 10) br % 10;
  69.         cStotina = (br / 100) br % 10;
  70.  
  71.         if(cJedinica + cDesetica + cStotina > 25)
  72.             break;
  73.  
  74.         if(br < 10)
  75.             a1[n1++] = br;
  76.         else if (br < 100)
  77.             a2[n2++] = br;
  78.         else
  79.             a3[n3++] = br;
  80.  
  81.         br = rand() % 10001;
  82.     }
  83.  
  84.     printf("A1 = {");
  85.     for (int i= 0; i < n1; i++) {
  86.         printf("%d, ", a1[i]);
  87.     }
  88.     printf("}\n");
  89.  
  90.  
  91.     printf("A2 = {");
  92.     for (int i= 0; i < n2; i++) {
  93.         printf("%d, ", a2[i]);
  94.     }
  95.     printf("}\n");
  96.  
  97.  
  98.     printf("A3 = {");
  99.     for (int i= 0; i < n3; i++) {
  100.         printf("%d, ", a3[i]);
  101.     }
  102.     printf("}\n");
  103.     return 0;
  104. }
  105. //4. Zadatak
  106. int main()
  107. {
  108.     int mat[256][256];
  109.     int n;
  110.  
  111.     printf("Unesite n\n");
  112.     scanf("%d", &n);
  113.  
  114.     for (int i = 0; i < n; i++)
  115.         for (int j = 0; j < n; j++) {
  116.             if (i == 0 || (i == n-1  && j < n/2)|| j == 0 || j == n-1 || j == n / 2) {
  117.                 mat[i][j] = 1;
  118.             }
  119.             else
  120.                 mat[i][j] = 0;
  121.         }
  122.  
  123.     for (int i = 0; i < n; i++) {
  124.         for (int j = 0; j < n; j++) {
  125.             printf("%d ", mat[i][j]);
  126.         }
  127.         printf("\n");
  128.     }
  129.     return 0;
  130. }
  131.  
  132. //5. Zadatak
  133. int main(int argc, char const *argv[])
  134. {
  135.    
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement