Advertisement
satriafu5710

Tukar Nilai dengan Pointer C++

Mar 2nd, 2021
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void tukarNilai(int *a, int *b)
  5. {
  6.  
  7.     int temp;
  8.  
  9.     temp = *a;
  10.     *a = *b;
  11.     *b = temp;
  12. }
  13.  
  14. int main()
  15. {
  16.  
  17.     int a, b;
  18.  
  19.     cout << "\t Tukar Nilai dengan Pointer \n\n";
  20.  
  21.     cout << " Masukkan Nilai a : ";
  22.     cin >> a;
  23.  
  24.     cout << " Masukkan Nilai b : ";
  25.     cin >> b;
  26.  
  27.     cout << "\n Nilai Sebelum Ditukar \n";
  28.     cout << "\n Nilai a : " << a;
  29.     cout << "\n Nilai b : " << b;
  30.  
  31.     tukarNilai(&a, &b);
  32.  
  33.     cout << "\n\n Nilai Setelah Ditukar \n";
  34.     cout << "\n Nilai a : " << a;
  35.     cout << "\n Nilai b : " << b;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement