Advertisement
nontawat1996

คูณเลข 100 หลัก

Mar 9th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.     char input[101]= {'\0'};
  7.     int a[101]= {0},b[101]= {0},temp[100001]= {0};
  8.     int i,j,n1,n2,t=0,d=0;
  9.     scanf("%s",input);
  10.     n1=strlen(input);
  11.     for(i=n1; i>=0; i--)
  12.     {
  13.         a[i]=input[d]-'0';
  14.         input[d]='\0';
  15.         d++;
  16.     }
  17.     d=0;
  18.     scanf("%s",input);
  19.     n2=strlen(input);
  20.     for(i=n2; i>=0; i--)
  21.     {
  22.         b[i]=input[d]-'0';
  23.         d++;
  24.     }
  25.     for(i=1; i<=n2; i++) // เอาไว้ วิ่ง b
  26.     {
  27.         d=i;
  28.         for(j=1; j<=n1; j++) // วิ่ง a
  29.         {
  30.             temp[d]=(b[i]*a[j])+t+temp[d];
  31.             t=0;
  32.             if(temp[d]>9)
  33.             {
  34.                 t=temp[d]/10;
  35.                 temp[d]%=10;
  36.             }
  37.             d++;
  38.         }
  39.     }
  40.     d=0;
  41.  
  42.     for(i=n1*n2; i>0; i--)
  43.     {
  44.         if(temp[i]!=d)
  45.         {
  46.             d++;
  47.             printf("%d",temp[i]);
  48.         }
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement