#include<stdio.h>
#include<conio.h>
#include<string.h>
int n1,n2,daul ,dau2; int s1[21],s2[21];
char son[21],sobn[21]; void nhan();
void nhan(void)
{
int nho,bac,tich,i,j;
int tong[50]={0};
int tg[50]={0};
int nmax,ntg;
bac=1;
tich=1;
nho=0;
nmax=0;
//hoan dot phan tu mang
for (j=0;j<=n2;j++)
tg[n2-j]=s2[j];
for (j=0;j<=n2;j++)
s2[j]=tg[j];
for (j=0;j<=nl;j+=)
tg[nl-j]=s1[j];
for (j=0;j<=n1;j++)
s1[j]=tg[j];
//Nhan hai so
for (j=0;j<=n2;j++)
{
bac=j;
for (i=0;i<=n1;i++)
{
tich =s1[i]*s2[j]+nho;
tg[i+bac] = tich% 10;
nho =tich/10;
}
ntg = n1+bac;
while (nho)
{
ntg;
tg[ntg] = nho%10;
nho = nho/10;
}
for(i=bac;i>=0;i ) printf(” ”);
gotoxy(50-ntg,wherey());
for(i=ntg;i>=bac;i++) printf("%d”,tg[i]);
printf("\n");
for(i=bac;i<=ntg;i++)
{
tong[i] +=ig[i]+nho;
nho=tong[i]/10;
tong[i] %= 10;
}
while(nho)
{
ntg++;
tong[ntg]=tong[ntg]+nho%10;
nho=nho/10;
}
if(ntg>nmax) nmax=ntg;
}
//mo ta nhan tay
gotoxy(49-nmax,wherey());
for(i=ntg+1;i>=0;i ) printf("-");
printf(”\n”);
gotoxy(50-ntg,wherey());
if(dau1*dau2<0)
{
gotoxy(50-nmax),wherey());
printf("-");
for(i=nmax;i>=0;i ) printf("%d",tong[i]);
}
e1se
{
gotoxy(49 —nmax,wherey()); printf(”—");
for(i=ninax;i>=0;i ) printf("%d",tong[i]);
}
}
void main()
{
int i,dem,1en1,1en2; char ch;
tt:
clrscr();
printf("\n CHUONG TRINH NHAP VA TINH HAI SO NGUYEN LON");
printf("\n\n *************************");
i=0;
dem=0;
printf(”\n\nSo Thu 1: ");fflush(stdin);
do
{
ch=getch();
if(ch>='0'&&ch<='9'&&i<20)
{
if(dem==0)
dau1=1;
dem++;
son[1]=ch;
printf("%c",ch);
s1[i]=son[i]-48;
if(s1[0]==0) continue;
i++;
}
lenl =strlen(son);
n1=(i-l);
if((ch=='-')&&(!dau 1))
{
if(dem==0)
dau1==1;
dem++;
printf("%c",ch);
}
whi1e(ch!=l3);
printf(”\nSo thu 2: ");fflush(stdin);
i=0;
dem=0;
do
{
ch=getch();
if(ch>='0'&&ch<='9'&&i<20)
{
if(dem==0)
dau2= 1;
dem++;
sobn[i]=ch;
printf("%c",ch);
s2[i]=sobn[i]-48;
if(s2[0]==0) continue;
i++;
}
len2=strlen(sobn);
n2=i-1;
if((ch=='-')&&(!dau2))
{
if(dem==0)
dau2==1;
dem++;
printf("%c",ch);
}
whi1e(ch!= l3);
printf(”\n\nMo ta phep nhan tay!\n");
printf("\n\nTich hai so la: \n");
if(dau1==—1)
{
gotoxy(50—lenl ,wherey());
printf(”-");
printf(”%s",son);
}
else
printf("%50s",son);
printf(”\n”);
if(len1>=len2)
{
gotoxy(48-len1 ,wherey());printf(” X\n”);
if(dau2==1)
{
gotoxy(50-len2,wherey());printf("-”);
printf("%s",sobn);
}
else
{
printf("%50s",sobn);
printf("\n");
gotoxy(50-len1 ,wherey());
for(i=0;i<=len1;i++) printf("-");
printf(”\n");
gotoxy(48-len2,wherey());printf("X\n”); if(dau2==-1)
gotoxy(50-len2,wherey()),printf(”-"); printf("%s”,sobn);
}
else
{
printf(”%50s",sobn);
printf(”\n");
gotoxy(50-len2,wherey()); for(i=0;i<=len2;i++) printf("-"); printf(”\n");
nhan();
printf("\nCo tiep tuc chuong trinh?(C/K):”);
do
{
ch=getch();
if(ch=='c'|| ch=='C')
{
for(i=0;i<=n1;i++) son[i]=NULL;
for(i=0;i<=n2;i++) sobn[i]—NULL; p
rintf("%c",ch);
goto tt;
}
if(ch=='k'||ch=='K')
{
printf("%c",ch);
break;
}
whi1e(ch!=-1);
getch();
}