-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPL_Assignment_2.cpp
125 lines (94 loc) · 2.54 KB
/
CPL_Assignment_2.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include<stdio.h>
#include<string.h>
#define SIZE 310
//#define PLUSE 1
//#define MINUS -1
typedef struct bigint_tag
{
char digits[SIZE];
int Sign_Bit;
int last_digit;
}Big_int;
void Initialise_big_int(Big_int *num)
{
num->digits[SIZE-1]='\0';
num->last_digit=SIZE-1;
}
void string_to_big_int(char no_1[], Big_int *num)
{
int i,j,l,z=0;
if(no_1[0]=='-')
{
num->Sign_Bit=-1;
z=1;
}
else
{
num->Sign_Bit=1;
l=strlen(no_1);
j=SIZE-1;
num->digits[SIZE-1]='\0';
for(i=l-1;i>=z;i--)
{
j--;
num->digits[j]=no_1[i];
}
num->last_digit=j;
}
}
void Print_Big_int(Big_int num)
{
int i;
int f=0;
for(i=num.last_digit;i<=SIZE-2;i++)
{
if(num.digits[i]!='0') //Prints the big_int
{
f=1;
break;
}
}
if(f==0)
{
num.Sign_Bit=1;
}
if(num.Sign_Bit==-1)
{
printf("-");
}
for(i=num.last_digit;i<=SIZE-2;i++)
{
printf("%c",num.digits[i]);
}
}
int main()
{
Big_int num_1,num_2,add,sub,mult;
char no_1[SIZE] ,no_2[SIZE];
printf("\n\t\t\t----------------------------------------------------------------------------\n");
printf("\t\t\t###########################################################################");
printf("\n\t\t\t############ ############");
printf("\n\t\t\t############ Representation of Bigint in C ############");
printf("\n\t\t\t############ ############");
printf("\n\t\t\t###########################################################################");
printf("\n\t\t\t---------------------------------------------------------------------------\n\n");
printf("Enter the First Number : ");
scanf("%s",no_1);
printf("Enter the Second Number : ");
scanf("%s",no_2);
Initialise_big_int(&num_1);
Initialise_big_int(&num_2);
Initialise_big_int(&add);
Initialise_big_int(&sub);
Initialise_big_int(&mult);
string_to_big_int(no_1,&num_1);
string_to_big_int(no_2,&num_2);
printf("\n\n");
Print_Big_int(num_1);
printf(" + ");
Print_Big_int(num_2);
//ans1=Add(num1,num2);
printf(" = ");
//Print_Big_int(ans1);
return 0;
}