13 Aralık 2014 Cumartesi

C# Obeb-Okek Hesaplama Kodları

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Obeb_Okek_Hesapla
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}



void obeb_okek(params string[] strDizi)
{

int[] sayilar = new int[strDizi.Length];

StrToInt(strDizi, sayilar);

int lim = sayilar.Max();

int obeb = 1, ekok = 1;

for (int i = 1; i <= lim; i++)
{

if (ModKontrol(i,sayilar))
{

obeb = i;

}
}

ekok = diziCarpim(sayilar) / obeb;

lblSonuc.Text = "Sonuç : Obeb = " + obeb.ToString() + " Ekok = " + ekok.ToString();

}

void StrToInt(string[] source, int[] converted)

{

for (int i = 0; i < source.Length; i++)

{

converted[i] = int.Parse(source[i]);

}
}

bool ModKontrol(int split, int[] arrayInt)

{

int count = 0;

for (int i = 0; i < arrayInt.Length; i++)
{

if (arrayInt[i] % split == 0)
{

count++;

}
}

if (arrayInt.Length == count) return true;

else return false;

}

int diziCarpim(int[] arrayInt)
{

int carpim = 1;

for (int i = 0; i < arrayInt.Length; i++)
{
carpim *= arrayInt[i];
}
return carpim;
}

private void btnHesapla_Click(object sender, EventArgs e)
{

string[] strSayilar = txtSayilar.Text.Split(',');

obeb_okek(strSayilar);

}
}
}
Paylaş:

0 yorum:

Yorum Gönder

Popüler

Son

Kategoriler

Arşiv