Apr 2, 2010 at 1:00am UTC
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
#include<iostream>
using namespace std;
#include<cstring>
#include<string>
#include<conio.h>
using namespace std;
typedef struct number{
char sign;
string adsoluteValue;
};
typedef struct result{
int digit;
int nho;
result *next;
};
int main()
{
result *ptr,*last;
last=NULL;
number firstNumber,secondNumber;
cin.get(firstNumber.sign);
getline(cin,firstNumber.adsoluteValue);
cin.get(secondNumber.sign);
getline(cin,secondNumber.adsoluteValue);
int m=(firstNumber.adsoluteValue).length();
int n=(secondNumber.adsoluteValue).length();
int min=(m>n)? n:m;
min--;
for (register int i=0;i<=m+n;i++){
ptr=new result[1];
ptr->next=last;
int singleNumber=0;
if (i<=min){
for (register int j=0;j<=i;j++){
char p[2];
char z[2];
p[0]=firstNumber.adsoluteValue.at(m-1-j);
p[1]='\0' ;
z[0]=secondNumber.adsoluteValue.at(n-1-i+j);
z[1]='\0' ;
singleNumber+=(atoi(p)*atoi(z));
}
}
if (i>min){
for (register int j=n;j>=0;--j){
char v[2];
char t[2];
v[0]=firstNumber.adsoluteValue.at(m+n-i-1-j);
v[1]='\0' ;
t[0]=secondNumber.adsoluteValue.at(j);
t[1]='\0' ;
singleNumber+=(atoi(v)*atoi(t));getch();
}}
if (i>0)
singleNumber+=last->nho;
ptr->digit=singleNumber%10;
ptr->nho=singleNumber/10;
last=ptr;
}
while (last!=NULL){
cout<<(last->digit);
last=last->next;
}
delete last,ptr;
getch();
return 0;
}
why i use getch() but the program still run and disappear without waiting for entering an character, somebody please help so thanks
Last edited on Apr 2, 2010 at 5:56am UTC
Apr 2, 2010 at 6:03am UTC
It seems not my point. when i leave codes from line 55 to 64, program work well. In other word, It stops to waite one character from keyboard. I use DEV-C++ to compile
and it appear an announcemet:
"This application has requested the Runtime to terminate it in an unusual way."
Last edited on Apr 2, 2010 at 6:14am UTC