fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node{
  4. int data;
  5. struct node *next;
  6. };
  7. struct node *head=NULL;
  8. void insertAtEnd()
  9. {
  10. struct node *newnode,*temp;
  11. newnode= malloc(sizeof(struct node));
  12. scanf("%d",&newnode->data);
  13. newnode->next=NULL;
  14. if(head=NULL)
  15. {
  16. head=newnode;
  17. }
  18. else{
  19. temp=head;
  20. while(temp->next!=NULL)
  21. {
  22. temp=temp->next;
  23. }
  24. temp->next=newnode;
  25. }
  26. }
  27. int main()
  28. { int n;
  29. printf("enter the number of nodes");
  30. scanf("%d",n);
  31. for (int i = 0; i < n; i++)
  32. {
  33. insertAtEnd();
  34. }
  35.  
  36. }
Success #stdin #stdout 0s 5460KB
stdin
Standard input is empty
stdout
enter the number of nodes