CPP   18

kvadrat

Guest on 30th June 2022 02:25:47 AM

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void swap(int x, int y) {
  6.   int tmp = x;
  7.   x = y;
  8.   y = tmp;
  9. }
  10.  
  11. void swap1(int *x, int *y) {
  12.   int tmp = *x;
  13.   *x = *y;
  14.   *y = tmp;
  15. }
  16.  
  17. void swap2(int &x, int &y) {
  18.   int tmp = x;
  19.   x = y;
  20.   y = tmp;
  21. }
  22.  
  23. inline int kvadrat(const int &x = 0) {
  24.   return x * x;
  25. }
  26.  
  27. float kvadrat(const float &x) {
  28.   return x * x;
  29. }
  30.  
  31.  
  32.  
  33.  
  34. int main() {
  35.   int x = 3;
  36.   float f = 2.1;
  37.  
  38.   x = 3 * 1 + 21;
  39.  
  40.   /* sljdflkjds f
  41.      lsjdflsjdl
  42.   */
  43.   cout << "Hello, world" << endl;
  44.   cout << "x = " << x << endl;
  45.  
  46.   cout << "Unesi f: ";
  47.   cin >> f;
  48.   cout << "f = " << f << endl;
  49.                          
  50.   int y = 1, z = 4;
  51.   int w(2);
  52.  
  53.   int *niz = new int[10];
  54.   for (int i = 0; i < 10; i++)
  55.     niz[i] = i * i;
  56.   for (int i = 0; i < 10; i++)
  57.     cout << niz[i] << endl;
  58.   delete [] niz;
  59.  
  60.  
  61.   cout << "x = " << x << endl;
  62.   cout << "y = " << y << endl;
  63.   swap(x, y);
  64.   cout << "x = " << x << endl;
  65.   cout << "y = " << y << endl;
  66.   swap1(&x, &y);
  67.   cout << "x = " << x << endl;
  68.   cout << "y = " << y << endl;
  69.   swap2(x, y);
  70.   cout << "x = " << x << endl;
  71.   cout << "y = " << y << endl;
  72.  
  73.   const int jedan = 1;
  74.   cout << kvadrat(jedan) << endl;
  75.   cout << kvadrat() << endl;
  76.  
  77.   cout << kvadrat(2.2f) << endl;
  78.  
  79.   return 0;
  80. }

Raw Paste


Login or Register to edit or fork this paste. It's free.