Witam,
Mam problem z zadaniem ze strony polski spoj, chodzi o zadanie " PA05_POT - czy umiesz potęgować ? ". Chodzi w nim między innymi by na ekranie konsoli wyświetlić cyfrę jedności liczby zapisanej dziesiętnie oczywiście podniesionej do danej potęgi.
Przykładowo:
- input: 2^3 , output: 8
- input: 3^3 , output: 7
Oto kod działa poprawnie, lecz na stronie wyskakuje błąd wykonania. Niestety nie jest to pierwsze zadanie w którym mam podobny problem. Jest ktoś w stanie pomoc w czym leży błąd ?
using System;
namespace PA05_POT___Czy_umiesz_potegowac
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int number_to_compound,compound,result;
for(int i=0;i<n;i++)
{
number_to_compound = Convert.ToInt32(Console.ReadLine());
compound = Convert.ToInt32(Console.ReadLine());
result = Compound(number_to_compound,compound);
result = Record_number_unity(result);
Console.WriteLine(result);
}
}
static int Compound(int number_to_compound,int compound)
{
int result = 1;
for(int i=0; i<compound; i++)
{
result *= number_to_compound;
}
return result;
}
static int Record_number_unity(int result)
{
result = result%10;
return result;
}
}
}