fork download
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct node
  5. {
  6. int data;
  7. struct node *next;
  8. }node;
  9.  
  10. void main()
  11. {
  12. node *head,*P;
  13. int n,i;
  14.  
  15. printf("Enter no. of elements\n");
  16. scanf("%d",&n);
  17.  
  18. printf("Enter %d data elements\n",n);
  19. head=(node*)malloc(sizeof(node));
  20. scanf("%d",&(head->data));
  21. head->next = NULL;
  22. P=head;
  23. for(i=1;i<n;i++)
  24. {
  25. P->next=(node*)malloc(sizeof(node));
  26. P=P->next;
  27. P->next=NULL;
  28. scanf("%d",&(P->data));
  29. }
  30. P = head;
  31. while(P!=NULL)
  32. {
  33. printf("%d",P->data);
  34. P=P->next;
  35. }
  36. }
Runtime error #stdin #stdout 0s 2428KB
stdin
5
1
2
4
5
6
stdout
Enter no. of elements
Enter 5 data elements
12456