Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<malloc.h>
- void phepcong(short *A,short nA,short *B,short nB, short *&C, short &nC )
- {
- short lengtC=0;
- short memoryNumber=0;
- short SumNode;
- if(nA==nB)
- {
- for(int i=nA;i>0;i--)
- {
- SumNode=A[i-1]+B[i-1]+memoryNumber;
- A[i-1]=SumNode%10;
- memoryNumber=SumNode/10;
- }
- }
- // xử lý phép cộng ở trên gán giá trị kết quả
- if(memoryNumber==0)
- {
- nC=nA;
- C=(short*)malloc(nC*sizeof(short));
- for(int i=0;i<nC;i++)
- {
- C[i]=A[i];
- }
- }
- else
- {
- nC=nA+1;
- C=(short*)malloc(nC*sizeof(short));
- C[0]=memoryNumber;
- for(int i=0;i<nA;i++)
- {
- C[i+1]=A[i];
- }
- }
- }
- void outputphepcong(short *C,int nC)
- {
- for(int i=0;i<nC;i++)
- {
- printf("%d",C[i]);
- }
- }
- void main()
- {
- short A[]={1,1,9};
- short B[]={1,8,2};
- short *C;
- short nC;
- phepcong(A,3,B,3,C,nC);
- printf("Ket qua la: \n");
- outputphepcong(C,nC);
- free(C);
- _getch();
- }
Add Comment
Please, Sign In to add comment