week 6
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct node
|
||||
{
|
||||
int number;
|
||||
struct node *next;
|
||||
} node;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
node *list = NULL;
|
||||
|
||||
for (int = 0; i < 3; i++)
|
||||
{
|
||||
node *n = malloc(sizeof(node));
|
||||
if (n == NULL)
|
||||
{return 1;}
|
||||
// n-> = NULL;
|
||||
(*n).number = get_int("Number: ");
|
||||
// n-> = NULL;
|
||||
(*)n.next = NULL;
|
||||
|
||||
// Prepend node to list
|
||||
n->next = list
|
||||
list =n;
|
||||
}
|
||||
|
||||
// Print Numbers
|
||||
node *ptr = list;
|
||||
while (ptr !=NULL)
|
||||
{
|
||||
printf("%i\n", ptr->number);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user