Advertisement
XCode-plus

Contoh Program Array of Structure

Dec 8th, 2016
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6.     int c;
  7.  
  8.     typedef struct{
  9.     long NIM;
  10.     char NAMA[25];
  11.     char KOTA[30];
  12.     }MAHASISWA;
  13.  
  14.     //Mendeklarasikan array A dengan tipe mahasiswa
  15.     //dan Jumlah elemennya tiga
  16.  
  17.     MAHASISWA A[3];
  18.  
  19.     //Mengisikan nilai pada elemen array
  20.  
  21.     for(c=0; c<3; c++){
  22.         cout << "NIM  : "; cin>>A[c].NIM;
  23.         cout << "NAMA : "; cin>>A[c].NAMA;
  24.         cout << "KOTA : "; cin>>A[c].KOTA;
  25.         cout << '\n';
  26.     }
  27.     //Menampilkan nilai yang telah dimasukan
  28.     //ke dalam elemen array
  29.  
  30.     for(c=0; c<3; c++){
  31.         cout << A[c].NIM << endl;
  32.         cout << A[c].NAMA<< endl;
  33.         cout << A[c].KOTA<< endl;
  34.         cout <<'\n';
  35.         }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement