|
Makale -
Kod Örnekleri
|
|
Yazar ugokhan
|
|
PerÅŸembe, 02 AÄŸustos 2007 00:18 |
|
Kullanıcı tarafından girilen iki sayının OBEB ve OKEK hesaplamalarını yapan program.
using System.Collections .Generic ;namespace ornek2 { class Program { static void Main(string[] args) { int a, b, secim, hedef,i; Console.Write("1. sayıyı girin : "); a = Convert.ToInt16(Console.ReadLine()); Console.Write("2. sayıyı girin : "); b = Convert.ToInt16(Console.ReadLine()); Console.Write("Bir İşlem Seçin. OBEB:[1], OKEK:[2] Seç : "); secim = Convert.ToInt16(Console.ReadLine()); if (secim==1) { hedef = (b > a) ? a : b; for(i=hedef; i>1; i--) { if (a % i == 0 && b % i == 0) break; } Console.WriteLine("OBEB({0},{1}) = {2}", a, b, i); } else if (secim == 2) { hedef = (b > a) ? b : a; for (i = hedef; hedef < (a * b); i += hedef) { if (i % a == 0 && i % b == 0) break; } Console.WriteLine("OKEK({0},{1}) = {2}", a, b, i); } } } }
|