Advertisement
nuray__alam

Problem 3

Dec 8th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct node
  4. {
  5. int value;
  6. struct node *next;
  7. }node;
  8. node *head=NULL;
  9. void insertfirst(int a)
  10. {
  11. node *n=(node*)malloc(sizeof(node));
  12. n->next=NULL;
  13. n->value=a;
  14. if(head==NULL){
  15. head=n;
  16. }
  17. else{
  18. n->next=head;
  19. head=n;
  20. }
  21. return;
  22. }
  23.  
  24. void display()
  25. {
  26. node *list=head;
  27. while(list!=NULL){
  28. printf("Data = %d\n",list->value);
  29. list=list->next;
  30. }
  31. return;
  32. }
  33. int main()
  34. {
  35. int i,n,x;
  36. printf("How many value you want to input: ");
  37. scanf("%d",&n);
  38. printf("\n\n");
  39. for(i=1;i<=n;i++){
  40. scanf("%d",&x);
  41. insertfirst(x);
  42. }
  43. display();
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement