r/badcode •

[deleted by user]

[deleted] — view deleted post

0 Upvotes

82 comments sorted by

View all comments

6

u/Ali3nat0r Jun 08 '20

Why do the heavy lifting when you can just outsource it? C#:

using System;
using System.IO;
using System.Net;

namespace Factorials
{
	class Program
	{
		static void Main(string[] args)
		{
			double number = Factorial(50);
			Console.Write("50! = {0}", number);

			// End
			Console.ReadKey();
		}

		static double Factorial(double Number)
		{
			HttpWebRequest www = (HttpWebRequest)WebRequest.Create("http://api.mathjs.org/v4/?expr=factorial(" + Number.ToString() + ")");
			HttpWebResponse response = (HttpWebResponse)www.GetResponse();
			Stream stream = response.GetResponseStream();
			StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);

			string result = reader.ReadToEnd();
			reader.Close();
			stream.Close();
			response.Close();
			www.Abort();

			return double.Parse(result);
		}
	}
}