27 Mayıs 2011 Cuma

C# Ekok Bulma Programı

Bu yazımda sizlere c# ta ekok ve ebob almanın kodlarını paylaşacağım.
EKOK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int x,y,z;
            
            Console.WriteLine("ekoku alınacak sayıyı giriniz");
            x =Convert.ToInt32(Console.ReadLine());
            y = Convert.ToInt32(Console.ReadLine());
            for (z = y; z > 0; z++)
            {
                if ((z % y == 0) && (z % x == 0))
                {
                    Console.WriteLine("ekok=" + z);
                    break;
                }
            }
            Console.ReadKey();
        }
    }
}



EBOB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int x,y,z;
            
            Console.WriteLine("ebobu alınacak sayıyı giriniz");
            x =Convert.ToInt32(Console.ReadLine());
            y = Convert.ToInt32(Console.ReadLine());
            for (z = y; z > 0; z--)
            {
                if ((y % z == 0) && (x % z == 0))
                {
                    Console.WriteLine("ebob=" + z);
                    break;
                }
            }
            Console.ReadKey();
        }
    }
}


Hiç yorum yok:

Yorum Gönder