fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct node{
  5. int data;
  6. struct node* next;
  7. };
  8.  
  9. struct node* head;
  10.  
  11. void Insert(int x);
  12. void Print();
  13.  
  14. int main(void){
  15.  
  16. head = NULL;
  17. printf("how many numbers?");
  18. int n,i,x;
  19. scanf("%d",&n);
  20.  
  21. for(i=0;i<n;i++){
  22. printf("Enter the number");
  23. scanf("%d",&x);
  24. Insert(x);
  25. Print();
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31. void Insert(int x){
  32.  
  33. struct node* temp = (struct node*)malloc(sizeof(struct node));
  34. temp->data = x;
  35. (*temp).next = head;
  36. head = temp;
  37. }
  38.  
  39. void Print(){
  40.  
  41. struct node* temp = head;
  42. printf("\nThe List is ");
  43. while(temp!=NULL){
  44. printf(" %d", temp->data);
  45. temp=temp->next;
  46. }
  47. }
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
how many numbers?