Files
CS50---Harvard/list1.c
T
2026-06-05 01:28:27 +00:00

40 lines
523 B
C

#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;
}