/* * プログラミング演習 第 9 回 * [例題 3] * (C) 2006 Hirohisa AMAN */ #include /* 構造体 node の宣言 */ struct node { int data; struct node* next; }; int main(void){ struct node sample[3]; struct node* head; struct node* p; int x, i; /* データを繰り返し読み込みながら連結していく */ for ( i = 0; i < 3; i++ ){ scanf("%d", &x ); sample[i].data = x; if ( i == 0 ){ sample[i].next = NULL; } else{ sample[i].next = &sample[i-1]; } } head = &sample[2]; /* リストの内容を表示 */ p = head; while ( p != NULL ){ printf("%d ", p->data); p = p->next; } printf("\n"); return 0; }