Promi_38

last digit of n to the power k

Jan 11th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6.     char n[99999];
  7.     long long k, i, prod = 1;
  8.     printf("Enter the number: ");
  9.     scanf("%s", n);
  10.     printf("Enter the power: ");
  11.     scanf("%lld", &k);
  12.    
  13.     if((n[strlen(n) - 1]) == '0' || (n[strlen(n) - 1]) == '1' || (n[strlen(n) - 1]) == '5' || (n[strlen(n) - 1]) == '6') printf("%c\n", (n[strlen(n) - 1]));
  14.     else if((n[strlen(n) - 1]) == '2')
  15.     {
  16.         if(k % 4 == 0) printf("6\n");
  17.         else if(k % 4 == 1) printf("2\n");
  18.         else if(k % 4 == 2) printf("4\n");
  19.         else if(k % 4 == 3) printf("8\n");
  20.     }
  21.     else if((n[strlen(n) - 1]) == '3')
  22.     {
  23.         if(k % 4 == 0) printf("1\n");
  24.         else if(k % 4 == 1) printf("3\n");
  25.         else if(k % 4 == 2) printf("9\n");
  26.         else if(k % 4 == 3) printf("7\n");
  27.     }
  28.     else if((n[strlen(n) - 1]) == '4')
  29.     {
  30.         if(k % 2 == 0) printf("6\n");
  31.         else if(k % 2 == 1) printf("4\n");
  32.     }
  33.     else if((n[strlen(n) - 1]) == '7')
  34.     {
  35.         if(k % 4 == 0) printf("1\n");
  36.         else if(k % 4 == 1) printf("7\n");
  37.         else if(k % 4 == 2) printf("9\n");
  38.         else if(k % 4 == 3) printf("3\n");
  39.     }
  40.     else if((n[strlen(n) - 1]) == '8')
  41.     {
  42.         if(k % 4 == 0) printf("6\n");
  43.         else if(k % 4 == 1) printf("8\n");
  44.         else if(k % 4 == 2) printf("4\n");
  45.         else if(k % 4 == 3) printf("2\n");
  46.     }
  47.     else if((n[strlen(n) - 1]) == '9')
  48.     {
  49.         if(k % 2 == 0) printf("1\n");
  50.         else if(k % 2 == 1) printf("9\n");
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment