Diktat_ProgKecilBhsC

# H int main kamus static char cc karakter yang

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ) { printf (&quot;T[%d]=%d \n&quot;, 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 (&quot;Isi dan print tabel untuk indeks 1..5 \n&quot;); /* isi dari pembacaan */ for (i = 0; i &lt; T.N; i++) { printf (&quot;Input Tabel ke-[%d] = &quot;, i); scanf (&quot;%d&quot;, &amp;(T.tab[i])); }; /* print : perhatikan passing parameter */ printTab (T); /* Increment : perhatikan passing parameter */ incTab (&amp;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 &lt; (*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 &lt; T.N; i++) { printf (&quot;T[%d]=%d \n&quot;, 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 (&quot;Isi dan print tabel untuk indeks 1..5 \n&quot;); /* isi dari pembacaan */ for (i = 0; i &lt; T.N; i++) { printf (&quot;Input Tabel ke-[%d] = &quot;, i); /* scanf (&quot;%d&quot;, (T.tab)+i ); */ scanf (&quot;%d&quot;, &amp; (*(T.tab +i)) ); }; /* print : perhatikan passing parameter */ printTab (T); /* Increment : perhatikan passing parameter */ incTab (&amp;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