Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct TArr
  6. {
  7.     __int64 MyArray[7];
  8. };
  9.  
  10. __int64 FindNumber(int i)
  11. {
  12.     __int64 Number = i, Prev = 0, Step = 1;
  13.     int Digit = i;
  14.     do
  15.     {
  16.         Step = Step * 10;
  17.         Number = Number + Step * ((Digit * 2) % 10 + Prev);
  18.         Prev = (Digit * 2) / 10;
  19.         Digit = Number / Step;
  20.     } while ((Digit != i) || (Prev != 0));
  21.     Number = Number - Digit * Step;
  22.     return Number;
  23. }
  24.  
  25. struct TArr GetArray()
  26. {
  27.     __int64 MyArr[7];
  28.     int i;
  29.     printf_s("This program searches for the smallest number, which, when you rearrange the last digit to the first one, is twice as large as the original\n");
  30.     printf_s("This is the list of required numbers :\n ");
  31.     for (i = 0; i < 7; i++)
  32.     {
  33.         MyArr[i] = FindNumber(i + 2);
  34.         printf_s("%d : %I64d\n", i + 2, MyArr[i]);
  35.     }
  36.     struct TArr MyArray = { MyArr[0],  MyArr[1],  MyArr[2],  MyArr[3],  MyArr[4],  MyArr[5],  MyArr[6] };
  37.     return MyArray;
  38. }
  39.  
  40. void ShowAnswer(TArr MyArray)
  41. {
  42.     __int64 Min = MyArray.MyArray[6];
  43.     for (int i = 0; i < 7; i++)
  44.         if (MyArray.MyArray[i] < Min)
  45.             Min = MyArray.MyArray[i];
  46.     printf_s("Minimum required number is : %I64d", Min);
  47. }
  48.  
  49. int main()
  50. {
  51.     TArr NumArr = GetArray();
  52.     ShowAnswer(NumArr);
  53.     int lol = 0;
  54.     scanf_s("%d", &lol);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement