Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that calculates N!/K! for given N and K (1<K<N).
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ex4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberN, numberK;
- string input;
- int sum = 0;
- do
- {
- Console.Write("Въведете число N: ");
- input = Console.ReadLine();
- }
- while (!(int.TryParse(input, out numberN) && (numberN > 0)));
- do
- {
- Console.Write("Въведете число K: ");
- input = Console.ReadLine();
- }
- while (!(int.TryParse(input, out numberK) && (numberK < numberN)));
- int factorialN = 1;
- for (int counter = 1; counter <= numberN; counter++)
- {
- factorialN *= counter;
- }
- Console.WriteLine("The factorial of {0} is {1}", numberN, factorialN);
- int factorialK = 1;
- for (int counter = 1; counter <= numberK; counter++)
- {
- factorialK *= counter;
- }
- Console.WriteLine("The factorial of {0} is {1}", numberK, factorialK);
- Console.WriteLine("N! / K! = {0}", factorialN/factorialK);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment