Kod:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Faktöriyel
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtSonuc;
private System.Windows.Forms.Button btnFaktoriyelHesaplama;
private System.Windows.Forms.Label lblSayi;
private System.Windows.Forms.Button txtFaktoriyelSonuc;
private System.Windows.Forms.Label lblSonuc;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override **** Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private **** InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.txtSonuc = new System.Windows.Forms.TextBox();
this.btnFaktoriyelHesaplama = new System.Windows.Forms.Button();
this.lblSayi = new System.Windows.Forms.Label();
this.txtFaktoriyelSonuc = new System.Windows.Forms.Button();
this.lblSonuc = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtSonuc
//
this.txtSonuc.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtSonuc.******** = new System.Drawing.Point(93, 64);
this.txtSonuc.Name = "txtSonuc";
this.txtSonuc.Size = new System.Drawing.Size(187, 20);
this.txtSonuc.TabIndex = 0;
//
// btnFaktoriyelHesaplama
//
this.btnFaktoriyelHesaplama.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnFaktoriyelHesaplama.******** = new System.Drawing.Point(93, 90);
this.btnFaktoriyelHesaplama.Name = "btnFaktoriyelHesaplama";
this.btnFaktoriyelHesaplama.Size = new System.Drawing.Size(187, 23);
this.btnFaktoriyelHesaplama.TabIndex = 1;
this.btnFaktoriyelHesaplama.Text = "Hesapla";
this.btnFaktoriyelHesaplama.Click += new System.EventHandler(this.btnFaktoriyelHesapla_Click);
//
// label2
//
this.lblSayi.AutoSize = true;
this.lblSayi.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
this.lblSayi.ForeColor = System.Drawing.Color.Firebrick;
this.lblSayi.******** = new System.Drawing.Point(11, 123);
this.lblSayi.Name = "label2";
this.lblSayi.Size = new System.Drawing.Size(76, 19);
this.lblSayi.TabIndex = 3;
this.lblSayi.Text = "Sonuç = ";
//
// txtFaktoriyelSonuc
//
this.txtFaktoriyelSonuc.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
this.txtFaktoriyelSonuc.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
this.txtFaktoriyelSonuc.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.txtFaktoriyelSonuc.******** = new System.Drawing.Point(93, 119);
this.txtFaktoriyelSonuc.Name = "txtFaktoriyelSonuc";
this.txtFaktoriyelSonuc.Size = new System.Drawing.Size(187, 23);
this.txtFaktoriyelSonuc.TabIndex = 4;
this.txtFaktoriyelSonuc.Text = "0";
//
// label1
//
this.lblSonuc.AutoSize = true;
this.lblSonuc.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
this.lblSonuc.ForeColor = System.Drawing.Color.Firebrick;
this.lblSonuc.******** = new System.Drawing.Point(12, 65);
this.lblSonuc.Name = "label1";
this.lblSonuc.Size = new System.Drawing.Size(52, 19);
this.lblSonuc.TabIndex = 5;
this.lblSonuc.Text = "Sayı :";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.lblSonuc);
this.Controls.Add(this.txtFaktoriyelSonuc);
this.Controls.Add(this.lblSayi);
this.Controls.Add(this.btnFaktoriyelHesaplama);
this.Controls.Add(this.txtSonuc);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Faktoriyel Hesaplama";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static **** Main()
{
Application.Run(new Form1());
}
private **** btnFaktoriyelHesapla_Click(object sender, System.EventArgs e)
{
try
{
double faktoriyelSonuc, counter, girilenSayi;
//girilen değeri double tipine çevirelim. Eğer girilen değer double tipine
//çevrilemezse işlem catch bloğuna atlayıp programdan çıkacak
girilenSayi = Convert.ToDouble(txtSonuc.Text);
counter = 1;
faktoriyelSonuc = 1;
//1 den başlayarak girilen sayıya kadar bütün sayıların çarpımını hesaplayarak
//girilen sayının faktoriyelini hesaplayalım
while (counter <= girilenSayi)
{
faktoriyelSonuc = faktoriyelSonuc * counter;
counter = counter + 1;
}
//Hesaplan faktoriyel değerini sonuç kutusuna yazdıralım
txtFaktoriyelSonuc.Text = Convert.ToString(faktoriyelSonuc);
}
catch (Exception)
{
MessageBox.Show("Bir Sayı girmelisiniz...", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}