HCF Calculation Over integer Array using c#.
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CalculationApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter number");
int num = int.Parse(Console.ReadLine());
int[] Arr = new int[num];
Console.WriteLine("Enter " + num + "number");
for (int i = 0; i < num; i++)
{
Arr[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("HCF Array");
int result = Arr[0];
for (int i = 1; i < Arr.Length; i++)
{
result = Calculation.Calculate(result, Arr[i]);
}
Console.WriteLine(result);
Console.ReadLine();
}
}
}
Calculation.cs
//HCF Calculation Over integer Array using c#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CalculationApp
{
public static class Calculation
{
public static int Calculate(int result, int value)
{
while (value > 0)
{
int temp = value;
value = result % value;
result = temp;
}
return result;
}
}
}
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteRegards,
Asp.Net Training in Chennai | Best Dot Net Training in Chennai
Selenium Coaching Institute in Chennai | Selenium Training in Chennai
Best Software Testing Training Institute in Chennai With Placement | Software Testing Training Institute in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Course in Chennai | PHP Training Institute in Chennai | PHP certification in Chennai