Girilen Sayının Mükemmel Sayı Olup Olmadığını Bulan Program

Mükemmel sayı nedir?
Kendisi hariç tüm pozitif bölenlerinin toplamına eşit olan sayıya denir.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {
            int tpl = 0;
            Console.Write("Bir sayı girin: ");
            int x = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <=x-1 ; i++)
            {
                if (x%i==0)
                {
                    tpl = tpl + i;
                }
            }
            if (x==tpl)
            {
                Console.WriteLine("Girdiğiniz sayı mükemmel sayıdır");
            }
            else
            {
                Console.WriteLine("Girdiğiniz sayı mükemmel sayı değildir");
            }
        }
    }
}




Yorum Gönder

0 Yorumlar