SHARE
TWEET

Untitled

a guest Feb 18th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///find
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. struct node
  6. {
  7.     int data;
  8.     struct node *next;
  9. };
  10.  
  11. int main()
  12. {
  13.     struct node *prev,*head,*p;
  14.     int n,i;
  15.     scanf("%d",&n);
  16.     head=NULL;
  17.     for(i=0;i<n;i++)
  18.     {
  19.         p=(struct node*)malloc(sizeof(struct node));
  20.         scanf("%d",&p->data);
  21.         p->next=NULL;
  22.         if(head==NULL){
  23.             head=p;
  24.         }
  25.         else{
  26.             prev->next=p;
  27.         }
  28.         prev=p;
  29.     }
  30.     struct node* ptr;
  31.     ptr=head;
  32.  
  33.     int dat;
  34.     printf("Enter data");
  35.     scanf("%d",&dat);
  36.     i=0;
  37.  
  38.     while(ptr!=NULL){
  39.         ++i;
  40.         if(ptr->data==dat){
  41.             printf("Found position at: %d\n",i);
  42.             break;
  43.         }
  44.         ptr=ptr->next;
  45.     }
  46.     if(ptr==NULL)
  47.     {
  48.         printf("Not found\n");
  49.     }
  50.  
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top