Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Root
- {
- class Program
- {
- public static bool RationalRoot(int num)
- {
- int sum = 0, n = 1;
- while (sum < num)
- {
- sum += n;
- n += 2;
- }
- return sum==num;
- }
- public static int HaveRootCount()
- {
- int count = 0;
- int input = -1;
- for (int i=0;i<4;i++)
- {
- while (input <= 0) // בדיקת קלט
- {
- Console.WriteLine("Type a positive number.");
- input = int.Parse(Console.ReadLine());
- }
- if (RationalRoot(input))
- {
- count++;
- }
- input = -1;
- }
- return count;
- }
- static void Main(string[] args)
- {
- int count = HaveRootCount();
- Console.WriteLine("{0} of the inputted numbers have a natural number root.",count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment