Advertisement
KillerBananaZ

Ultima cifra a^b

Jan 19th, 2018
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. Ultima cifra a lui a^b
  2.  
  3. unsigned uc(unsigned a, unsigned b)
  4. {
  5. unsigned c=a%10;
  6. if(c==0 || c==1 || c==5 || c==6)
  7. return c;
  8. else
  9. switch(c)
  10. {
  11. case 2:
  12. {
  13. switch(b%4)
  14. {
  15. case 0:
  16. return 6;
  17. case 1:
  18. return 2;
  19. case 2:
  20. return 8;
  21. case 3:
  22. return c;
  23. }
  24. }
  25. case 3:
  26. {
  27. switch(b%4)
  28. {
  29. case 0:
  30. return 6;
  31. case 1:
  32. return 2;
  33. case 2:
  34. return 8;
  35. case 3:
  36. return c;
  37. }
  38. }
  39. case 4:
  40. {
  41. switch(b%4)
  42. {
  43. case 0:
  44. return 6;
  45. case 1:
  46. return 2;
  47. case 2:
  48. return 8;
  49. case 3:
  50. return c;
  51. }
  52. }
  53. case 7:
  54. {
  55. switch(b%4)
  56. {
  57. case 0:
  58. return 6;
  59. case 1:
  60. return 2;
  61. case 2:
  62. return 8;
  63. case 3:
  64. return c;
  65. }
  66. }
  67. case 8:
  68. {
  69. switch(b%4)
  70. {
  71. case 0:
  72. return 6;
  73. case 1:
  74. return 2;
  75. case 2:
  76. return 8;
  77. case 3:
  78. return c;
  79. }
  80. }
  81. case 9:
  82. {
  83. switch(b%4)
  84. {
  85. case 0:
  86. return 6;
  87. case 1:
  88. return 2;
  89. case 2:
  90. return 8;
  91. case 3:
  92. return c;
  93. }
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement