M!k
Joined: 22 Apr 2002 Posts: 871 Helped: 79
|
21 Sep 2009 0:25 Re: what is the final digit in the number 947^362? |
|
|
|
|
OK, here're your homeworks:
you can use the proggi below to calculate the last digit.
The trick is this: if you just wanted to know the last digit, your calculation can also be reduced to the last digit. So we won't calculate 947^362, but 7^362.
Calculating the power means multiplying the basis with itself exponent times.
So the sequence would be:
7^1 = 7
7^2 = 49
7^3 = 343
7^4 = 2401
7^5 = 16807
7^6 = 117649
.
.
.
7^362 = a very big number
As that very big number (requires special libraries) is not interesting we can again reduce the result of each multiplication to the last digit.
So the sequence is like that (compare to the last digit of sequence above):
1 * 7 = 7 --> 7
7 * 7 = 49 --> 9
9 * 7 = 63 --> 3
3 * 7 = 21 --> 1
1 * 7 = 7 --> 7
7 * 7 = 49 --> 9
.... (repeat 362 times in total) --> Result: 9
Btw. you'll recognize that the sequence of the last digit is always: 7 9 3 1
So you can also calculate 362 / 4 = 90.5. The result after 0.5 of this sequence is 9
| Code: |
void main(void)
{
unsigned int basis;
unsigned int exponent;
unsigned char lastdigit;
unsigned int counter;
basis = 947;
exponent = 362;
printf("\nCalculating the last digit of: %d^%d\n", basis, exponent);
basis = lastdigit = basis % 10; // reduce to last digit, e.g. 947 --> 7
for(counter = 2; counter <= exponent; counter++)
{
lastdigit = lastdigit * basis;
lastdigit = lastdigit % 10; // reduce result to last digit
// printf("\nExponent: %d Last Digit: %d", counter, lastdigit);
// getch();
}
printf("\n\nResult: %d\n", lastdigit);
}
|
|
|