Проверить, какая из последовательностей изменяется быстрее - C#
Формулировка задачи:
Добрый день. Проверить,какая с последовательностей изменяется быстрее n! или a^n. Числа a и n вводятся пользователем. результат вывести таблицей вида:
1!-a^1
...
(n-1)!-a^(n-1)
Вот мой код,a^n считает отлично.. а вот с факториалами какая-то ерунда. Помогите пожалуйста
int a, n, b;
Console.WriteLine("Введите значение a");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Введите значение n");
n = int.Parse(Console.ReadLine());
int factorial = 1;
int i = 0;
while (i < n)
{
i++;
b = Convert.ToInt32(Math.Pow(a, n));
factorial *= i;
//Console.WriteLine("{0,3} в степени {1,3} равняется{2,3}", a, n, b);
n++;
Console.WriteLine("{0,3}- {1}", factorial, b);
}Решение задачи: «Проверить, какая из последовательностей изменяется быстрее»
textual
Листинг программы
using System;
namespace Laba8part3
{
class Program
{
static void Main()
{
try
{
int n;
double a;
Console.WriteLine("Введите значение a");
a = double.Parse(Console.ReadLine());
Console.WriteLine("Введите значение n");
n = int.Parse(Console.ReadLine());
int i = 0;
int x = 1;
int fact = 1;
int b;
do {
b = Convert.ToInt32(Math.Pow(a,x));
fact *= x; //fact=fact*x;
x++;
Console.WriteLine("{0}-{1}",fact,b);
i++;
} while (i<n);
/* while (i < n)
{
fact *= x;
b = Convert.ToInt32(Math.Pow(a, x));
x++;
Console.WriteLine("{0}-{1}", fact, b);
i++;
}
*/
/* for (;i<n;i++) {
fact *= x;
b = Convert.ToInt32(Math.Pow(a,x));
x++;
Console.WriteLine("{0}-{1}", fact, b);
}
*/
}
catch (OverflowException exc1)
{
Console.WriteLine(exc1.Message);
}
catch (FormatException exc2)
{
Console.WriteLine(exc2.Message);
}
catch (Exception exc3) {
Console.WriteLine(exc3.Message);
}
}
}
}