Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     Console.WriteLine("Enter a no");
     int no = int.Parse(Console.ReadLine());
     BigInterger fact = 1;
     if (no > 0)
     {
         for (int i = 1; i <= no; i++)
         {
             fact = fact * i;
         }
         Console.WriteLine("{0}!={1}", no, fact);
         string str = fact.ToString();
         string[] ss = str.Split('0');
         int count = 0;
         for (int i = ss.Length - 1; i >= 0; i--)
         {
             if (ss[i] == "")
                 count = count + 1;
             else
                 break;
         }
         Console.WriteLine("No of trailing zeroes are = {0}", count);
     }
     else
     {
         Console.WriteLine("Can't calculate factorial of negative no");
     }
     Console.ReadKey();
 }
Ejemplo n.º 2
0
		static void Main(string[] args) {
			string[] numbers = File.ReadAllLines("input.txt");
			BigInteger[] nonstring = new BigInteger[numbers.Length];
			//Creates a BigInterger array the same length of the string array.
			//I am reading the numbers as strings because they are easy to manipulate.
			
			for (int i = 0; i < numbers.Length; i++) {
				nonstring[i] = new BigInteger(BigInteger.Parse(numbers[i]));
				Console.WriteLine(numbers[i]);
			}
			
			BigInteger sum = new BigInterger(0);
			
			for (int i = 0; i < nonstring.Length; i++) {
				sum += nonstring[i];
				Console.WriteLine(sum);
			}
			
			Console.WriteLine(sum);
			Console.Read();		
		}