-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_linked_list.c
More file actions
52 lines (42 loc) · 883 Bytes
/
sum_linked_list.c
File metadata and controls
52 lines (42 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *head1=NULL;
struct node *head2=NULL;
void create_linked_list(int n){
struct node *p=(struct node*)malloc(sizeof(struct node));
int i;
head2=p;
for(i=0;i<n-1;++i){
printf("Enter the %d node data\n",i+1);
scanf("%d",&p->data);
p->next=(struct node*)malloc(sizeof(struct node));
p=p->next;
}
printf("Enter the %d node data\n",i+1);
scanf("%d",&p->data);
p->next=NULL;
}
void display(struct node *head){
struct node *p=head;
while(p!=NULL){
printf("%d ",p->data);
p=p->next;
}printf("\n");
}
int main(){
int m,n;
printf("Enter the size of first linked list\n");
scanf("%d",&m);
create_linked_list(m);
head1=head2;
printf("Enter the size of second linked list\n");
scanf("%d",&n);
create_linked_list(n);
display(head1);
display(head2);
return 0;
}