-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2.c
More file actions
66 lines (57 loc) · 892 Bytes
/
Copy pathp2.c
File metadata and controls
66 lines (57 loc) · 892 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#define true 1
#define false 0
typedef struct node
{
int data;
struct node *next;
}node;
node *head;
void traverse(node *);
int main()
{
node *ptr, *cpt;
ptr = (node *)malloc(sizeof(node));
scanf("%d", &ptr->data);
ptr->next = NULL;
head = ptr;
while(true)
{
int bool = true;
char a[50];
cpt = (node *)malloc(sizeof(node));
cpt->data = 0;
scanf("%s", &a);
int len = strlen(a);
for(int i=0; i<len; i++)
{
if(a[i]<'0' || a[i]>'9')
{
bool = false;
}
}
if(!bool)
break;
else
{
for(int i=0; i<len; i++)
{
cpt->data += ((int)(a[i]-'0') * (int)pow(10, len-(i+1)));
}
}
cpt->next = NULL;
ptr->next = cpt;
ptr = cpt;
}
traverse(head);
}
void traverse(node *ptr)
{
if(ptr==NULL)
return;
traverse(ptr->next);
printf("%d\n", ptr->data);
}