fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct node_type {
  4. int data;
  5. struct node_type *next;
  6. } node;
  7.  
  8. int main()
  9. {
  10. typedef node *list;
  11. list head, temp;
  12. char ch;
  13. int n;
  14. head = NULL;
  15. printf("enter Data?(y/n)\n");
  16. scanf("%c", &ch);
  17.  
  18. while ( ch == 'y' || ch == 'Y')
  19. {
  20. printf("\nenter data:");
  21. scanf("%d", &n);
  22. temp = (list)malloc(sizeof(node));
  23. temp->data = n;
  24. temp->next = head;
  25. head = temp;
  26. printf("enter more data?(y/n)\n");
  27.  
  28. scanf(" %c", &ch);
  29.  
  30. }
  31. temp = head;
  32. while (temp != NULL)
  33. {
  34. printf("%d", temp->data);
  35. temp = temp->next;
  36. }
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 2188KB
stdin
y
2
y
3
n
stdout
enter Data?(y/n)

enter data:enter more data?(y/n)

enter data:enter more data?(y/n)
32