-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab4_4.c
79 lines (72 loc) · 1.41 KB
/
lab4_4.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
struct node
{
struct node *link;
int info;
} * start;
void print_now(struct node *beg, struct node *dig)
{
printf("Pair: \n");
while (beg != dig)
{
printf(" %d", beg->info);
beg = beg->link;
}
}
void create_list(int data)
{
struct node *q, *tmp;
tmp = (struct node *)malloc(sizeof(struct node));
tmp->info = data;
tmp->link = NULL;
if (start == NULL)
{
start = tmp;
}
else
{
q = start;
while (q->link != NULL)
{
q = q->link;
}
q->link = tmp;
}
}
void sum_node()
{
struct node *q, *q2, *q3;
for (q = start; q != NULL; q = q->link)
{
for (q2 = start; q2->link != q->link; q2 = q2->link)
{
q3 = q2;
int sum = 0;
while (q3 != q)
{
sum += q3->info;
q3 = q3->link;
}
if (sum == q->info)
{
print_now(q2, q);
}
}
}
}
int main()
{
int no_node;
start = NULL;
printf("Enter the number of nodes : ");
scanf("%d", &no_node);
int data;
for (size_t i = 0; i < no_node; i++)
{
printf("Enter data\n");
scanf("%d", &data);
create_list(data);
}
sum_node();
}