forked from R0HITKUMAR/webDevUsingGSheets.sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListNoAdd.c
More file actions
56 lines (54 loc) · 1.11 KB
/
linkedListNoAdd.c
File metadata and controls
56 lines (54 loc) · 1.11 KB
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
// find out the addition of two given link list 125+85 =210 1->2->5 8->5
#include<stdio.h>
#include<math.h>
#include "linkedList.h"
void add(struct node **list1,struct node **list2)
{
struct node *p,*q;
int c1=0,c2=0,temp;
float sum1=0,sum2=0;
p = (*list1);
q = (*list2);
while (p!=NULL)
{
sum1+=p->info *pow(10,c1);
c1+=1;
p = p->next;
}
while (q!=NULL)
{
sum2+=q->info *pow(10,c2);
c2+=1;
q = q->next;
}
temp = sum1+sum2;
printf("%d",temp);
linkedListFormation(temp);
}
void linkedListFormation(int temp)
{
int n;
struct node *P;
P = NULL;
while (temp!=0)
{
n = temp%10;
temp = temp/10;
InsBeg(&P,n);
}
printf("\nAddition Linked List : ");
Traverse(&P);
}
void main()
{
struct node *START1,*START2;
START1=NULL;
START2=NULL;
InsBeg(&START1,1);
InsBeg(&START1,2);
InsBeg(&START1,5);
InsBeg(&START2,8);
InsBeg(&START2,5);
printf("Sum of Lists : ");
add(&START1,&START2);
}