Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. __int64 FindNumber(int i) {
  3.     __int64 Number = i;
  4.     __int64 Prev = 0;
  5.     __int64 Step = 1;
  6.     __int64 Digit = i;
  7.     do {
  8.         Step *= 10;
  9.         Number += Step * ((Digit * 2) % 10 + Prev);
  10.         Prev = (Digit * 2) / 10;
  11.         Digit = Number / Step;
  12.     } while ((Digit != i) || (Prev != 0));
  13.     Number -= Digit * Step;
  14.     return Number;
  15. }
  16. void GetArray(__int64 *MyArr) {
  17.     printf_s("This program searches for the smallest number, which, when you rearrange the last digit\n"
  18.                           "to the first one, is twice as large as the original\n");
  19.     printf_s("This is the list of required numbers :\n");
  20.     for (int i = 0; i < 7; i++) {
  21.         MyArr[i] = FindNumber(i + 2);
  22.         printf_s("%d : %I64d\n", i + 1, MyArr[i]);
  23.     }
  24. }
  25. void ShowAnswer(__int64 *MyArray) {
  26.     __int64 Min = MyArray[6];
  27.     for (int i = 0; i < 7; i++)
  28.         if (MyArray[i] < Min)
  29.             Min = MyArray[i];
  30.     printf_s("Minimum required number is : %I64d", Min);
  31. }
  32. int main(){
  33.     __int64 ArrayNumber[7];
  34.     GetArray(ArrayNumber);
  35.     ShowAnswer(ArrayNumber);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement