Advertisement
Guest User

Domaci

a guest
Dec 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int Pozitivna ( int X )
  4. {
  5.  
  6. if ( X >= 0 )
  7. {
  8.  
  9. return X ;
  10.  
  11. }
  12.  
  13. else
  14. {
  15.  
  16. int Y = X - (2*X) ;
  17. return Y ;
  18.  
  19. }
  20.  
  21. }
  22.  
  23. int main()
  24. {
  25.  
  26. printf("Unesite broj kolone: " ) ; int Kolona ; scanf("%d" , &Kolona ) ;
  27. printf("Unesite broj elemenata iz te kolone koje treba sabrati: " ) ; int X ; scanf("%d" , &X ) ;
  28.  
  29. int PlusKolona = Pozitivna ( Kolona ) ;
  30.  
  31. int PrviBroj ;
  32. int PrviInkrement = (PlusKolona+1)*2 ;
  33. int DrugiInkrement = PrviInkrement ;
  34. int Zbir ;
  35.  
  36. int k1 = 1 ;
  37.  
  38. while ( k1 < X )
  39. {
  40. k1++;
  41. PrviInkrement = PrviInkrement + 2 ;
  42. DrugiInkrement = DrugiInkrement + PrviInkrement ;
  43.  
  44. }
  45.  
  46. if ( PlusKolona == Kolona )
  47. {
  48. PrviBroj = (Kolona+1)*(Kolona+1) ;
  49. }
  50.  
  51. else
  52. {
  53. PrviBroj = Kolona*Kolona+1 ;
  54. }
  55.  
  56. if ( X == 1 )
  57. {
  58. printf("Zbir je %d" , PrviBroj ) ;
  59. }
  60.  
  61. else
  62. {
  63. Zbir = PrviBroj * X + DrugiInkrement ;
  64. Zbir = Zbir - 4 ;
  65.  
  66. printf("Zbir je: %d" , Zbir ) ;
  67. }
  68.  
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement