Can't understand what is wrong
Oct 12, 2014 at 7:09pm UTC
I have got a task to create a program which would take two whole numbers up to 100 digits each and print out their difference in full digits without shortening. I wrote this little program which seems to work only for small numbers so I guess it's some C principal I don't understand. Looking for an answer.
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
#include <stdio.h>
#include <conio.h>
#include <iostream>
const int size = 200;
double ivestis();
int laips(int , int );
int main(){
char * mass;
double C;
mass = new char [size];
int flag = 0;
C = ivestis();
for (int i=0; i<=size; i++) mass[i] = '*' ;
for (int j=0; j<=size; j++){
mass[j] = C / laips(10,size-j);
C -= mass[j] * laips(10,size-j);
}
for (int k=0; k<=size; k++) if (mass[k] != 0 && mass[k] != '*' ) {
flag = k;
break ;}
for (int l=flag; l<=size; l++) printf("%d" , mass[l]);
getch();
return 0;
}
double ivestis(){
double A,B;
printf("Number A: " );
std::cin >> A;
printf("Number B: " );
std::cin >> B;
return (A-B);
}
int laips(int sk, int n){
int back = 1;
for (int i=1; i<=n; i++) back *= sk;
return back;
}
Oct 12, 2014 at 9:42pm UTC
Oct 12, 2014 at 10:28pm UTC
Topic archived. No new replies allowed.