-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSummator.c
More file actions
77 lines (76 loc) · 1.54 KB
/
Summator.c
File metadata and controls
77 lines (76 loc) · 1.54 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
void summator(int *a, int *b,int max,int t)
{
int i,counter=0,digit=0;
int *c = (int*)calloc(sizeof(int),max+1);
for(i=0; i<max; i++)
{
counter = a[max-i-1] +b[max-i-1];
if(counter>=10)
{
digit=counter/10;
counter=counter%10;
}
c[max-i]+=counter;
c[max-i-1]+=digit;
digit=0;
counter=0;
}
for(i=0; i<max+5; i++)
printf("-");
printf("\n");
printf("c: ");
for(i=0; i<max+1; i++)
printf("%d",*(c+i));
free(c);
}
int main()
{
setlocale(0,"");
int n,i,m,t=0,max,dif1=0,dif2=0;
printf("Введите размер числа 1: ");
scanf("%d",&n);
printf("Введите размер числа 2: ");
scanf("%d",&m);
if(n>m)
{
max=n;
dif1=max-m;
}
else if(n<m)
{
max=m;
dif2=max-n;
}
else
{
max=m;
}
int *a =(int*)calloc(sizeof(int),max);
int *b =(int*)calloc(sizeof(int),max);
printf("Введите a: ");
for(i=dif2+1; i<=n+dif2; i++)
{
printf("\n");
scanf("%d",a+i);
}
printf("Введите b: ");
for(i=dif1+1; i<=m+dif1; i++)
{
printf("\n");
scanf("%d",b+i);
}
printf("a: ");
for(i=0; i<n+dif2; i++)
printf("%d",*(a+i));
printf("\n");
printf("b: ");
for(i=0; i<m+dif1; i++)
printf("%d",*(b+i));
printf("\n");
summator(a,b,max,t);
free(a);
free(b);
return 0;
}