Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Node
- {
- int x;
- char name[10];
- struct Node *ptr;
- }node;
- node *head = NULL;
- node *temp = NULL;
- int main()
- {
- int i, n, j;
- printf("Number of friends:");
- scanf("%d", &n);
- for(i=1; i<=n; i++)
- {
- node *q = (node*)malloc(sizeof (node));
- printf("\nEnter Name:");
- scanf("%s", q -> name);
- printf("Enter His Phone No:");
- scanf("%d", &q -> x);
- q -> ptr = NULL;
- if(head == NULL)
- {
- head = q;
- }
- else
- {
- temp = head;
- while(temp -> ptr != NULL)
- {
- temp = temp -> ptr;
- }
- temp -> ptr = q;
- }
- }
- temp = head;
- printf("\nYou have %d friends in your list\n\n", n);
- for(j=1; temp!= NULL; j++)
- {
- printf("Friend %d:\n", j);
- printf("Name:%s\n", temp->name);
- printf("Phone No:%d\n\n", temp->x);
- temp = temp->ptr;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement