Advertisement
DASBD72

11112bignumber

Oct 1st, 2020
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. /* 2016/09/22 */
  3. int first4(int x){
  4.     return x/10000;
  5. }
  6. int last4(int x){
  7.     /* The operator % in C computes the remainder after division.
  8.     For example, the answer of 23%7 will be 2.*/
  9.     return x%10000;
  10. }
  11. int first8(int x){
  12.     return x/100000000;
  13. }
  14. int last8(int x){
  15.     return x%100000000;
  16. }
  17. int shift4(int x){
  18.     return x*10000;
  19. }
  20. int main(void){
  21.     int x;
  22.     int a, b;
  23.     int c1, c2, c3;
  24.     /* Assume that the input is always an 8-digit positive integer. */
  25.     scanf("%d", &x);
  26.     a = first4(x);
  27.     b = last4(x);
  28.     c3 = last4(b*b);
  29.     c2 = last8(2*a*b + first4(b*b) + shift4(last4(a*a)));
  30.     c1 = first4(a*a)+first8(2*a*b + first4(b*b) + shift4(last4(a*a)));
  31.     printf("%4d%08d%04d", c1, c2, c3);  
  32.     /* %04d will display a 4-digit number and add 0 as padding before the number if necessary */
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement