Chen Sayısı ve Mükemmel sayı bulma — Csharp

Chen Sayısı ve Mükemmel sayı bulma — Csharp


chen

 

[code lang=”csharp”]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox2.Items.Clear();
#region mükemmel sayılar
if (radioButton1.Checked == true)
{

int top = 0;
int sayı1 = int.Parse(textBox1.Text);
int sayı2 = int.Parse(textBox2.Text);
for (int i = sayı1; i <= sayı2; i++)
{
top = 0;
for (int j = 1; j < i; j++)
{

if (i % j == 0)
{
top = top + j;
}

}
if (i == top)
{
listBox1.Items.Add(i);

}

}
}
#endregion

#region chen sayılar
if (radioButton2.Checked == true)
{
int sayi1, sayi2, toplam, a;
sayi1 = int.Parse(textBox1.Text);
sayi2 = int.Parse(textBox2.Text);
for (int i = sayi1; i <= sayi2; i++)
{
a = 0;
int chen = i + 2;
toplam = 0;
for (int j = 1; j <= i; j++)
{
if (i % j == 0)
toplam = toplam + 1;
}
for (int l = 1; l <= chen; l++)
{
if (chen % l == 0)
a = a + 1;
}
if (toplam == 2)
listBox1.Items.Add(i.ToString());
if (a == 2 && toplam == 2)
listBox2.Items.Add("(" + i + "," + chen + ")".ToString());
}
}
#endregion

}
}
}
[/code]

chen1

Projeyi İNDİR

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir