Diktat_ProgKecilBhsC

H int main kamus static char cc karakter yang

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ) { printf ("T[%d]=%d \n", i, T.tab[i]); } } /* File : bacatab2.c */ /* latihan array dinamis dan statis : mengisi dg baca, menulis */ /* Latihan passing parameter tabel */ typedef struct { int *tab; int N; } TabInt; /* prototype */ void incTab (TabInt *T ); /* increment setiap element tabel */ void printTab (TabInt T); /* print tabel */ int main () { /* Kamus */ int i; TabInt T; /* Program */ T.tab = (int *) malloc(3*sizeof(int)); T.N = 3; printf ("Isi dan print tabel untuk indeks 1..5 \n"); /* isi dari pembacaan */ for (i = 0; i < T.N; i++) { printf ("Input Tabel ke-[%d] = ", i); scanf ("%d", &(T.tab[i])); }; /* print : perhatikan passing parameter */ printTab (T); /* Increment : perhatikan passing parameter */ incTab (&T); printTab (T); return 0; } /* Body prototype */ void incTab (TabInt * T) /* increment setiap element tabel */ { /* Kamus lokal */ int i; /* Algoritma */ /* traversal: print */ for (i = 0; i < (*T).N; i++) { (*T).tab[i] = (*T).tab[i] + 1; } } void printTab (TabInt T) /* print tabel */ {/* Kamus lokal */ int i; /* Algoritma */ /* traversal: print */ for (i = 0; i < T.N; i++) { printf ("T[%d]=%d \n", i, T.tab[i]); } } /* File : bacatab2.c */ /* latihan array dinamis dan statis : mengisi dg baca, menulis */ /* Latihan passing paramter tabel */ typedef struct { int *tab; int N; } TabInt; /* prototype */ void incTab (TabInt *T ); /* increment setiap element tabel */ void printTab (TabInt T); /* print tabel */ int main () {/* Kamus */ int i; TabInt T; /* Program */ T.tab = (int *) malloc(3*sizeof(int)); T.N = 3; printf ("Isi dan print tabel untuk indeks 1..5 \n"); /* isi dari pembacaan */ for (i = 0; i < T.N; i++) { printf ("Input Tabel ke-[%d] = ", i); /* scanf ("%d", (T.tab)+i ); */ scanf ("%d", & (*(T.tab +i)) ); }; /* print : perhatikan passing parameter */ printTab (T); /* Increment : perhatikan passing parameter */ incTab (&T); printTab (T); return 0; } /* Body prot...
View Full Document

This document was uploaded on 03/15/2014 for the course IF 2030 at Institut Teknologi Bandung.

Ask a homework question - tutors are online