11 Temmuz 2011 Pazartesi

C# ÖRNEK : While Döngüsü Kullanımı

Not ortalamasını bulan C# programı (-1 de ğeri girilene kadar notları okur).
using System;
using System.Windows.Forms;
class NotOrt
 {
public static void Main(string[] args)
 {
 float ortalama;
int sayac=0, notu, toplam=0;
 Console.WriteLine("Notu giriniz (Exit : -1)");
string str = Console.ReadLine();
 notu = Int32.Parse(str);
 while(notu!=-1) {
 toplam += notu; ++sayac;
 Console.WriteLine("Notu giriniz (Exit : -1)");
 str = Console.ReadLine();
 notu = Int32.Parse(str);
 };
string s;
if (sayac==0) s = "Not girilmedi!";
else s = "Sinif ort. = "+(float)toplam/sayac;
 MessageBox.Show(s,"Sonuclar",
 MessageBoxButtons.OK,MessageBoxIcon.Information);
 }
 }

0 yorum:

Yorum Gönder