1 / 12

Elazığ, 2012

C#. Elazığ, 2012. Fonksiyon ve Altprogram. double fak( byte x ) //fonksiyon satırları { byte i; double s; s = 1; for (i = 1; i <= x; i++) s = s * i; return s; }.

stash
Télécharger la présentation

Elazığ, 2012

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# Elazığ, 2012

  2. Fonksiyon ve Altprogram double fak(byte x) //fonksiyon satırları { byte i; double s; s = 1; for (i = 1; i <= x; i++) s = s * i; return s; } private void textBox1_TextChanged(object sender, EventArgs e) { byte sayı; double sonuç; sayı = byte.Parse(textBox1.Text); sonuç = fak(sayı); //gönderme satırı label1.Text = sonuç.ToString(); }

  3. 1-20 arası sayıların faktöryeli privatevoid Form1_Load(objectsender, EventArgs e) { byte i; for (i = 1; i <= 20; i++) listBox1.Items.Add(fak(i).ToString()); }

  4. f(n,r) private void button1_Click(object sender, EventArgs e) { byte n, r; double s; n = byte.Parse(textBox2.Text); r = byte.Parse(textBox3.Text); s = fak(n) / (fak(r) * fak((byte)(n - r))); MessageBox.Show("n-r kombinasyonu:"+s.ToString()); }

  5. Hipotenüs – iki değer gönderelim double hipotenus(double x, double y) { returnMath.Sqrt(x*x+y*y); } privatevoid Form1_Load(objectsender, EventArgs e) { MessageBox.Show(hipotenus(3, 4).ToString()); MessageBox.Show(hipotenus(5, 12).ToString()); }

  6. N tane sayının kareleri toplamı double kare_topla(paramsdouble[] x) { double t = 0; int i; for (i = 0; i <= x.Length - 1; i++) t = t + Math.Pow(x[i], 2); return t; } private void button1_Click(object sender, EventArgs e) { double sonuç; sonuç = kare_topla(5,12); MessageBox.Show(sonuç.ToString()); }

  7. Birden fazla değer geri gönderme void ayir2(double x, refinttam, ref double ondalik) { tam = (int)x; //sayının tam kısmını al ondalik = x - tam; } private void button1_Click(object sender, EventArgs e) { double x, z = 0; int y = 0; x = 145.39; ayir2(x, ref y, ref z); MessageBox.Show("tam kısım " + y.ToString()+"ondalık kısım "+z.ToString()); }

  8. Birden fazla değer geri gönderme void ayir2(double x, outint tam, out double ondalik) { tam = (int)x; //sayının tam kısmını al ondalik = x - tam; } private void button1_Click(object sender, EventArgs e) { double x, z = 0; int y = 0; x = 145.39; ayir2(x, out y, out z); MessageBox.Show("tam kısım " + y.ToString()+"ondalık kısım "+z.ToString()); }

  9. Aynı isme sahip prosedür = Overload int topla(int x, int y) { MessageBox.Show("2 parametreli olan fonk çalışıyor"); return x+y; } int topla(int x, int y, int z) { MessageBox.Show("3 parametreli olan fonk çalışıyor"); return x + y + z; } private void button1_Click(object sender, EventArgs e) { MessageBox.Show(topla(5,6).ToString()); MessageBox.Show(topla(5,6,7).ToString()); } Parametre veya türü farklı olabilir.

  10. Olaylara ortak kod yazma private void button1_Click(object sender, EventArgs e) { MessageBox.Show("merhaba"); } private void button2_Click(object sender, EventArgs e) { button1_Click(sender, e); //button1 deki kodu çağır }

  11. Olaylara ortak kod yazma privatevoidislem_yap(objectsender, EventArgs e) { MessageBox.Show("merhaba"); }

  12. Uygulama Soruları • Alt programa gönderilen N tane sayının karekökleri toplamını bulan prog? • Alt programa gönderilen sayının karekökünü ve küp kökünü geri gönderen prog?

More Related