Big Integer : Many Digit Addition with Integer Data Type (Penjumlahan Banyak Digit dengan Tipe Data Integer)
We take the first number 57575757, the second number 12345678
In the program number will be stored in each array element.
The first number
5
|
7
|
5
|
7
|
5
|
7
|
5
|
7
|
The second number
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
Having obtained such that every sum of digits performed live. But here happened the outcome of the sum is also stored role in every element of the array. As the above example will occur 7 + 8 = 15. Number 15 aka the last element stored in the array. So we must be smart - smart play with the computer. We use modulo to get the number 5. So that is not stored in the memory array 15. The next smaller digit we add 1. Because 10 of 15 had been added in front of him. As usual summation in primary schools.
Based on that logic could be a program that can count up the number of big integers. That is the number of type integer, but has plenty of appropriate digits we want.
Writing can be made like this :
void aritmatika::penjumlahan(){
for(int i=(digit-1);i>=0;i--){
jumlah[i]=jumlah[i]+input1[i]+input2[i];
if (jumlah[i] >9 && i !=0){
jumlah[i]=jumlah[i]%10;
jumlah[i-1]=jumlah[i-1]+1;
}
}
}
Easy right opponent? Next let us work. For all the code themselves can be downloaded here
Jadilah yang pertama mengomentari
Post a Comment