1 Mayıs 2012 Salı

Dosyalama (Telefon Rehberi)

using System;


using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;



namespace Metotlar

{

class Program

{

static int seçim;

static string AdıSoyadı, Telefon, AdSoyad, Kayıt="Yok";



static void menü()

{

Console.BackgroundColor = ConsoleColor.Yellow;

Console.ForegroundColor = ConsoleColor.Blue;

Console.Clear();

Console.CursorTop = 5;Console.CursorLeft = 35;

Console.Write("ANA MENÜ");

Console.CursorTop = 7; Console.CursorLeft = 30;

Console.Write("1-KAYIT EKLEME");

Console.CursorTop = 8; Console.CursorLeft = 30;

Console.Write("2-KAYIT LİSTELEME");

Console.CursorTop = 9; Console.CursorLeft = 30;

Console.Write("3-KAYIT ARAMA");

Console.CursorTop = 10; Console.CursorLeft = 30;

Console.Write("4-KAYIT SİLME");

Console.CursorTop = 11; Console.CursorLeft = 30;

Console.Write("5-KAYIT DÜZELTME");

Console.CursorTop = 12; Console.CursorLeft = 30;

Console.Write("6-ÇIKIŞ");

Console.CursorTop = 14; Console.CursorLeft = 30;

Console.Write("SEÇİMİNİZ [1-6] = ");

seçim = Convert.ToInt16(Console.ReadLine());

}









static void KayıtEkle()

{

string DosyaYolu = @"D:\Rehber.TXT";

FileInfo Dosyaadı = new FileInfo(DosyaYolu);

if (Dosyaadı.Exists)

{

StreamWriter DosyaYaz = Dosyaadı.AppendText();

Console.Clear();

Console.Write("Adı Soyadı = ");

AdıSoyadı = Console.ReadLine();

Console.Write("Telefon = ");

Telefon = Console.ReadLine();

DosyaYaz.WriteLine(AdıSoyadı);

DosyaYaz.WriteLine(Telefon);

DosyaYaz.Close();

Console.WriteLine("Bilgiler Dosyaya Kaydedildi");

}

else

{

StreamWriter DosyaYaz = Dosyaadı.CreateText();

Console.Clear();

Console.Write("Adı Soyadı = ");

AdıSoyadı = Console.ReadLine();

Console.Write("Telefon = ");

Telefon = Console.ReadLine();

DosyaYaz.WriteLine(AdıSoyadı);

DosyaYaz.WriteLine(Telefon);

DosyaYaz.Close();

Console.WriteLine("Bilgiler Dosyaya Kaydedildi");

}



}





static void KayıtListele()

{

string DosyaYolu = @"D:\Rehber.TXT";

FileInfo Dosyaadı = new FileInfo(DosyaYolu);

Console.Clear();



StreamReader DosyaOku = Dosyaadı.OpenText();



AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();



while (AdıSoyadı != null)

{

Console.Write(AdıSoyadı);

Console.CursorLeft = 15;

Console.WriteLine(Telefon);

AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();

}



DosyaOku.Close();

}







static void KayıtAra()

{

string DosyaYolu = @"D:\Rehber.TXT";

FileInfo Dosyaadı = new FileInfo(DosyaYolu);

Console.Clear();



StreamReader DosyaOku = Dosyaadı.OpenText();



Console.Write("Aranılan Kişinin Adı Soyadı = ");

AdSoyad = Console.ReadLine();



AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();



while (AdıSoyadı != null)

{

if (AdSoyad == AdıSoyadı)

{

Console.WriteLine("Aranılan Telefon = " + Telefon);



Kayıt = "Var";

}



AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();



}

DosyaOku.Close();

if (Kayıt == "Yok") Console.WriteLine("Aranılan Kayıt Yok");



}







static void KayıtSilme()

{



string DosyaYolu = @"D:\Rehber.TXT";

string DosyaYolu2 = @"D:\Yedek.TXT";



FileInfo Dosyaadı = new FileInfo(DosyaYolu);

FileInfo Dosyaadı2 = new FileInfo(DosyaYolu2);

StreamReader DosyaOku = Dosyaadı.OpenText();

StreamWriter DosyaYaz = Dosyaadı2.CreateText();



Console.Clear();

Console.Write("Silinecek Kişinin Adı Soyadı = ");

AdSoyad = Console.ReadLine();



AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();



while (AdıSoyadı != null)

{

if (AdıSoyadı == AdSoyad)

{

Kayıt = "Var";

}

else

{

DosyaYaz.WriteLine(AdıSoyadı);

DosyaYaz.WriteLine(Telefon);

}



AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();

}

DosyaOku.Close();

DosyaYaz.Close();

Dosyaadı.Delete();

Dosyaadı2.MoveTo(@"D:\Rehber.TXT");

if (Kayıt == "Yok") Console.WriteLine("Silinecek Kayıt Yok");

}







static void KayıtDüzeltme()

{



string DosyaYolu = @"D:\Rehber.TXT";

string DosyaYolu2 = @"D:\Yedek.TXT";



FileInfo Dosyaadı = new FileInfo(DosyaYolu);

FileInfo Dosyaadı2 = new FileInfo(DosyaYolu2);

StreamReader DosyaOku = Dosyaadı.OpenText();

StreamWriter DosyaYaz = Dosyaadı2.CreateText();



Console.Clear();

Console.Write("Düzeltilecek Kişinin Adı Soyadı = ");

AdSoyad = Console.ReadLine();



AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();



while (AdıSoyadı != null)

{

if (AdıSoyadı == AdSoyad)

{

Console.Write("Düzeltilecek Kişinin Telefonu = ");

Telefon = Console.ReadLine();

Kayıt = "Var";

}



DosyaYaz.WriteLine(AdıSoyadı);

DosyaYaz.WriteLine(Telefon);





AdıSoyadı = DosyaOku.ReadLine();

Telefon = DosyaOku.ReadLine();

}

DosyaOku.Close();

DosyaYaz.Close();

Dosyaadı.Delete();

Dosyaadı2.MoveTo(@"D:\Rehber.TXT");

if (Kayıt == "Yok") Console.WriteLine("Silinecek Kayıt Yok");

}





static void Main(string[] args)

{

start:

menü();



if (seçim == 6) Environment.Exit(0);



if (seçim == 1) KayıtEkle();

if (seçim == 2) KayıtListele();

if (seçim == 3) KayıtAra();

if (seçim == 4) KayıtSilme();

if (seçim == 5) KayıtDüzeltme();



Console.Write("Ana Menüye Dönmek İçin Bir Tuşa Basınız");

Console.ReadKey();

goto start;



}

}

}



Metotlar

Klavyeden girilen 2 sayının toplamını bulan programı yazınız.




static int sayı1, sayı2, toplam;



static void giriş()

{

Console.Clear();

Console.Write("1.Sayıyı Gir = ");

sayı1 = Convert.ToInt16(Console.ReadLine());

Console.Write("2.Sayıyı Gir = ");

sayı2 = Convert.ToInt16(Console.ReadLine());

}



static void işlem()

{

toplam = sayı1 + sayı2;

}



static void sonuç()

{

Console.Write(sayı1 + " + " + sayı2 + " = " + toplam);

}



static void Main(string[] args)

{

giriş();

işlem();

sonuç();

Console.ReadKey();

}







Klavyeden girilen 2 sayıyı kullanıcının isteğine göre 4 işlem uygulayan programı yazınız.

static int sayı1, sayı2, sonuç, seçim;

static void menü()

{

Console.BackgroundColor = ConsoleColor.Yellow;

Console.ForegroundColor = ConsoleColor.Blue;

Console.Clear();

Console.CursorTop = 5;Console.CursorLeft = 30;

Console.Write("ANA MENÜ");

Console.CursorTop = 7; Console.CursorLeft = 30;

Console.Write("1-TOPLAMA");

Console.CursorTop = 8; Console.CursorLeft = 30;

Console.Write("2-ÇIKARMA");

Console.CursorTop = 9; Console.CursorLeft = 30;

Console.Write("3-ÇARPMA");

Console.CursorTop = 10; Console.CursorLeft = 30;

Console.Write("4-BÖLME");

Console.CursorTop = 11; Console.CursorLeft = 30;

Console.Write("5-ÇIKIŞ");

Console.CursorTop = 13; Console.CursorLeft = 30;

Console.Write("SEÇİMİNİZ [1-5] = ");

seçim = Convert.ToInt16(Console.ReadLine());





}



static void giriş()

{

Console.Clear();

Console.Write("1.Sayıyı Gir = ");

sayı1 = Convert.ToInt16(Console.ReadLine());

Console.Write("2.Sayıyı Gir = ");

sayı2 = Convert.ToInt16(Console.ReadLine());

}

static void toplama()

{

sonuç = sayı1 + sayı2;

Console.WriteLine(sayı1 + " + " + sayı2 + " = " + sonuç);

}

static void çıkarma()

{

sonuç = sayı1 - sayı2;

Console.WriteLine(sayı1 + " - " + sayı2 + " = " + sonuç);

}

static void çarpma()

{

sonuç = sayı1 * sayı2;

Console.WriteLine(sayı1 + " * " + sayı2 + " = " + sonuç);

}

static void bölme()

{

sonuç = sayı1 / sayı2;

Console.WriteLine(sayı1 + " / " + sayı2 + " = " + sonuç);

}

static void Main(string[] args)

{

start:

menü();



if (seçim == 5) Environment.Exit(0);



giriş();



if (seçim == 1) toplama();

if (seçim == 2) çıkarma();

if (seçim == 3) çarpma();

if (seçim == 4) bölme();



Console.Write("Ana Menüye Dönmek İçin Bir Tuşa Basınız");

Console.ReadKey();

goto start;

} 

Klavyeden 5 öğrencinin adısoyadı ve notu giriliyor. Adısoyadına ve notuna göre sıralayıp listeleyen programı yazınız.



static string[] isim = new string[6];

static int[] notu = new int[6];

static string gisim;

static int gnotu;



static void giriş()

{

for (int sayaç = 1; sayaç < 6; sayaç++)

{

Console.Write(sayaç + ".Kişi =");

isim[sayaç] = Console.ReadLine();

Console.Write(isim[sayaç] + "'nin Notu =");

notu[sayaç] = Convert.ToInt16(Console.ReadLine());

}

}

static void isimsıralama()

{

for (int i = 1; i < 6; i++)

for (int k = 1; k < 6; k++)

if (string.Compare(isim[i], isim[k]) == -1)

{

gisim = isim[i];

isim[i] = isim[k];

isim[k] = gisim;



gnotu = notu[i];

notu[i] = notu[k];

notu[k] = gnotu;

}

}

static void notsıralama()

{

for (int i = 1; i < 6; i++)

for (int k = 1; k < 6; k++)

if (notu[i] < notu[k])

{

gisim = isim[i];

isim[i] = isim[k];

isim[k] = gisim;



gnotu = notu[i];

notu[i] = notu[k];

notu[k] = gnotu;

}

}

static void listeleme()

{

Console.WriteLine("İsimler Notlar");



for (int sayaç = 1; sayaç < 6; sayaç++)

{

Console.Write(isim[sayaç]);

Console.CursorLeft = 15;

Console.WriteLine(notu[sayaç]);

}

Console.ReadKey();

}

static void Main(string[] args)

{

giriş();

isimsıralama();

listeleme();

notsıralama();

listeleme();

}

5 Nisan 2012 Perşembe

Dizi Değişkenler Sıralama

Klavyeden girilen 5 notu sıralayarak listeleyen program.

int[] notu = new int[6];
int gnotu;

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(sayaç + ".kişinin Notu =");
notu[sayaç] = Convert.ToInt16(Console.ReadLine());
}

for (int i = 1; i < 6; i++)
for (int k = 1; k < 6; k++)
if (notu[i] < notu[k])
{
gnotu = notu[i];
notu[i] = notu[k];
notu[k] = gnotu;
}

Console.WriteLine("Sıralanmış Notlar");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.WriteLine(notu[sayaç]);
}
Console.ReadKey();

Klavyeden girilen 5 ismi sıralayarak listeleyen program.

string[] isim = new string[6];
string gisim;

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(sayaç + ".Kişi =");
isim[sayaç] = Console.ReadLine();
}

for (int i = 1; i < 6; i++)
for (int k = 1; k < 6; k++)
if (string.Compare(isim[i], isim[k]) == -1)
{
gisim = isim[i];
isim[i] = isim[k];
isim[k] = gisim;
}

Console.WriteLine("Sıralanmış İsimler ");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(isim[sayaç]);
}
Console.ReadKey();


Klavyeden girilen 5 ismi ve notu ismine ve notuna göre sıralayarak listeleyen program.

string[] isim = new string[6];
int[] notu = new int[6];
string gisim;
int gnotu;

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(sayaç + ".Kişi =");
isim[sayaç] = Console.ReadLine();
Console.Write(isim[sayaç] + "'nin Notu =");
notu[sayaç] = Convert.ToInt16(Console.ReadLine());
}

for (int i = 1; i < 6; i++)
for (int k = 1; k < 6; k++)
if (string.Compare(isim[i], isim[k]) == -1)
{
gisim = isim[i];
isim[i] = isim[k];
isim[k] = gisim;

gnotu = notu[i];
notu[i] = notu[k];
notu[k] = gnotu;

}

Console.WriteLine("İsimler Notlar");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(isim[sayaç]);
Console.CursorLeft = 15;
Console.WriteLine(notu[sayaç]);
}

for (int i = 1; i < 6; i++)
for (int k = 1; k < 6; k++)
if (notu[i] < notu[k])
{
gisim = isim[i];
isim[i] = isim[k];
isim[k] = gisim;

gnotu = notu[i];
notu[i] = notu[k];
notu[k] = gnotu;

}

Console.WriteLine("İsimler Notlar");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(isim[sayaç]);
Console.CursorLeft = 15;
Console.WriteLine(notu[sayaç]);
}

Console.ReadKey();

30 Mart 2012 Cuma

Dizi Değişkenler Listeleme

Dizi Değişkenler
Bir değişken adı altında birden fazla bilgiyi saklamak istersek kullanılan değişken türüdür. Özellikle bilgilerin sıralanması ve listelenmesi istenen durumlarda dizi değişkenler kullanılır. Böylelikle aynı tür bilgilerin bellek bölgesine yerleştirilmesi, işlem yapılması, ulaşılması kolay ve hızlı olacaktır.

Dizi Değişkenin Tanımlanması (Global Değişken Olarak Tanımlanır)
Dizi_Değişken_Türü [] Dizi_Değişken_Adı = new Dizi_Değişken_Türü [Eleman Sıra No+1];

Örnek : string [] Adı = new string [6];
6 elemanın adını saklayabileceğimiz bellek bölgesini rezerv eder.

RAM Bellek Bölgesi
Eleman Sıra No Adı
0
1 Mehmet
2 Ahmet
3 Demet
4 Meral
5 Merve

Örnek : Klavyeden girilen 5 ismi listeleyen programı yazınız.
string [] isim = new string[6];
for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(sayaç + ".Kişinin Adı =");
isim[sayaç] = Console.ReadLine();
}

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.WriteLine(sayaç + ".Kişi =" + isim[sayaç]);
}
Console.ReadKey();

Örnek : Klavyeden girilen 5 notu listeleyen programı yazınız.

int[] notu = new int[6];

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(sayaç + ".Kişinin Notu =");
notu[sayaç] = Convert.ToInt16(Console.ReadLine());
}

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.WriteLine(sayaç + ".Kişinin Notu =" + notu[sayaç]);
}
Console.ReadKey();


Örnek : 5 kişilik sınıftaki öğrencilerin adı ve yıl sonu notları giriliyor. Girilen bilgileri listeleyen program.

string[] isim = new string[6];
int[] notu = new int[6];

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(sayaç + ".Kişi =");
isim[sayaç] = Console.ReadLine();
Console.Write(isim[sayaç] + "'nin Notu =");
notu[sayaç] = Convert.ToInt16(Console.ReadLine());
}
Console.WriteLine("İsimler Notlar");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Write(isim[sayaç]);
Console.CursorLeft = 15;
Console.WriteLine(notu[sayaç]);
}
Console.ReadKey();


Bir sınıftaki 5 öğrencinin Adı Soyadı, 2 Yazılı, 1 Sözlü ve Ödev notu klavyeden giriliyor. Not ortalaması ve geçip geçmediği bulunarak, önce dersi geçenleri, sonra kalanları listeleyen programı yazınız.

string[] isim = new string[6];
int[] yazılı1 = new int[6];
int[] yazılı2 = new int[6];
int[] sözlü = new int[6];
int[] ödev = new int[6];
double[] ortalama = new double[6];
string[] sonuç = new string[6];

for (int sayaç = 1; sayaç < 6; sayaç++)
{
Console.Clear();
Console.Write(sayaç + ".Kişi =");
isim[sayaç] = Console.ReadLine();
Console.Write(isim[sayaç] + "'nin 1.Yazılı Notu =");
yazılı1[sayaç] = Convert.ToInt16(Console.ReadLine());
Console.Write(isim[sayaç] + "'nin 2.Yazılı Notu =");
yazılı2[sayaç] = Convert.ToInt16(Console.ReadLine());
Console.Write(isim[sayaç] + "'nin Sözlü Notu =");
sözlü[sayaç] = Convert.ToInt16(Console.ReadLine());
Console.Write(isim[sayaç] + "'nin Ödev Notu =");
ödev[sayaç] = Convert.ToInt16(Console.ReadLine());

ortalama[sayaç] = (yazılı1[sayaç] + yazılı2[sayaç] + sözlü[sayaç] + ödev[sayaç]) / 4;

if (ortalama[sayaç] < 45) sonuç[sayaç] = "Kaldı"; else sonuç[sayaç] = "Geçti";
}

Console.Clear();
Console.WriteLine("Geçenler");
Console.WriteLine("İsimler 1.Yazılı 2.Yazılı Sözlü Ödev Ortalama Sonuç");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
if (ortalama[sayaç] >= 45)
{
Console.Write(isim[sayaç]);
Console.CursorLeft = 15;
Console.Write(yazılı1[sayaç]);
Console.CursorLeft = 25;
Console.Write(yazılı2[sayaç]);
Console.CursorLeft = 35;
Console.Write(sözlü[sayaç]);
Console.CursorLeft = 45;
Console.Write(ödev[sayaç]);
Console.CursorLeft = 55;
Console.Write(ortalama[sayaç]);
Console.CursorLeft = 65;
Console.WriteLine(sonuç[sayaç]);
}
}

Console.WriteLine("Kalanlar");
Console.WriteLine("İsimler 1.Yazılı 2.Yazılı Sözlü Ödev Ortalama Sonuç");

for (int sayaç = 1; sayaç < 6; sayaç++)
{
if (ortalama[sayaç] < 45)
{
Console.Write(isim[sayaç]);
Console.CursorLeft = 15;
Console.Write(yazılı1[sayaç]);
Console.CursorLeft = 25;
Console.Write(yazılı2[sayaç]);
Console.CursorLeft = 35;
Console.Write(sözlü[sayaç]);
Console.CursorLeft = 45;
Console.Write(ödev[sayaç]);
Console.CursorLeft = 55;
Console.Write(ortalama[sayaç]);
Console.CursorLeft = 65;
Console.WriteLine(sonuç[sayaç]);
}
}
Console.ReadKey();

23 Mart 2012 Cuma

For Komutu 2

Örnek 11: 1’den 10’a kadar olan sayıların karekök, kare ve küplerini listeleyen program

Console.Clear();
Console.CursorLeft = 10; Console.Write("Sayı");
Console.CursorLeft = 20; Console.Write("Karekök");
Console.CursorLeft = 30; Console.Write("Kare");
Console.CursorLeft = 40; Console.WriteLine("Küp");
Console.CursorLeft = 10;
Console.Write("------------------------------------");
for (int sayaç = 1; sayaç <11; sayaç++)
{
Console.CursorTop = sayaç + 1;
Console.CursorLeft = 10; Console.Write(sayaç);
Console.CursorLeft = 20;
Console.Write(Math.Sqrt(sayaç).ToString("#,###.00"));
Console.CursorLeft = 30;
Console.Write(Math.Pow(sayaç, 2));
Console.CursorLeft = 40;
Console.Write(Math.Pow(sayaç, 3));
}
Console.ReadKey();
}


Örnek 12: Çarpım tablosunun ilk 5 sırasını görüntüleyen programı hazırlayınız.

Console.Clear();
for (int sayaç = 1; sayaç <11; sayaç++)
{
Console.CursorTop = sayaç + 1;
Console.CursorLeft = 5;
Console.Write(1 + " * " + sayaç + " = " + 1 * sayaç);
Console.CursorLeft = 20;
Console.Write(2 + " * " + sayaç + " = " + 2 * sayaç);
Console.CursorLeft = 35;
Console.Write(3 + " * " + sayaç + " = " + 3 * sayaç);
Console.CursorLeft = 50;
Console.Write(4 + " * " + sayaç + " = " + 4 * sayaç);
Console.CursorLeft = 65;
Console.Write(5 + " * " + sayaç + " = " + 5 * sayaç);
for (int salise=1;salise<10000000;salise++);
}
Console.ReadKey();

Örnek 13: Klavyeden girilen ismi 5 defa yazan programı yazınız.

Console.Clear();
string isim;
Console.Write("Bir İsim Gir = ");
isim = Console.ReadLine();

for (int sayaç = 1; sayaç <6; sayaç++)
{
Console.WriteLine(sayaç + " - " + isim);
}
Console.ReadKey();



Örnek 14: Klavyeden girilen ismin uzunluğu kadar ismi yazan programı yazınız.

string isim;
int uzunluk;

Console.Clear();
Console.Write("Bir İsim Gir = ");
isim = Console.ReadLine();

uzunluk = Convert.ToInt16(isim.Length.ToString());

for (int sayaç = 1; sayaç < uzunluk+1; sayaç++)
{
Console.WriteLine(sayaç + " - " + isim);
for (int salise = 0; salise < 10000000; salise++);
}
Console.ReadKey();



Örnek 15: Klavyeden girilen sayının faktöryelini bulan programı hazırlayınız.

int sayı, faktöryel=1;
Console.Clear();
Console.Write("Bir Sayı Gir = ");
sayı = Convert.ToInt16(Console.ReadLine());

for (int sayaç = 1; sayaç {
faktöryel = faktöryel * sayaç;
}

Console.Write("Faktöryel = " + faktöryel);
Console.ReadKey();


Örnek 16: Klavyeden girilen 3 basamaklı sayıların basamaklarını ayrı ayrı listeleyen program

int sayı, ilk, orta, son;
Console.Clear();
Console.Write("Bir Sayı Gir = ");
sayı = Convert.ToInt16(Console.ReadLine());

ilk = sayı / 100;
son= sayı % 10;
orta = (sayı - ilk * 100) / 10;

Console.WriteLine("Yüzler Basamağı = " + ilk);
Console.WriteLine("Onlar Basamağı = " + orta);
Console.WriteLine("Birler Basamağı = " + son);
Console.ReadKey();


Örnek 17: 100’den 999’a kadar olan sayılardan basamaklarının küpleri toplamı kendisine eşit olan sayıları bulan programı yazınız.

int ilk, orta, son;
double küp;
Console.Clear();
for (int sayı = 100; sayı < 1000; sayı++)
{
ilk = sayı / 100;
son= sayı % 10;
orta = (sayı - ilk * 100) / 10;
küp = Math.Pow(ilk, 3) + Math.Pow(orta, 3) + Math.Pow(son, 3);
if (sayı==küp)
Console.WriteLine("Basamakları Küpleri Toplamı = " +sayı);
}
Console.ReadKey();


Örnek 18: 3’den 50’ye kadar olan asal sayıları bulan programı yazınız.

int kalan;
bool asal;
Console.Clear();
for (int sayı = 3; sayı < 51; sayı++)
{
asal=true;
for (int bölen = 2; bölen < sayı; bölen++)
{
kalan = sayı % bölen;
if (kalan == 0) asal = false;
}
if (asal == true) Console.WriteLine(sayı + " asaldır");
}
Console.ReadKey();

16 Mart 2012 Cuma

For Komutu 1

DÖNGÜ KOMUTLARI
Döngüler-Tekrarlı İşlemler
Aynı işlemin birden fazla tekrarlandığı durumlara döngü denir.
FOR KOMUTU

Belirli bir sayıda tekrarlı işlem yapılacağı zamanlar kullanılır.
Kullanım Şekli
for (int sayaç = başlangıç değeri; sayaç < bitiş değeri; artış miktarı)
{
Tekrarlanacak Komutlar;
}

Örnek: Herhangi bir işlemi 10 defa tekrarlayan For komutunu yazınız. for (int sayaç = 1; sayaç < 11; sayaç++)
{ Tekrarlanacak Komutlar;
}

Örnek 1:İsminizi 10 defa yazdıran programı yazınız.
for (int sayaç = 1; sayaç < 11; sayaç++)
{
Console.WriteLine(" Mehmet Kuşcu");
}
Console.ReadKey();

Örnek 2: Klavyeden girilen ismi 10 defa yazdıran programı yazınız.
string isim;
Console.Write("Bir İsim Giriniz= ");
isim = Console.ReadLine();
for (int sayaç = 1; sayaç < 11; sayaç++)
{
Console.WriteLine(sayaç + “-“ + isim);
}
Console.ReadKey();

Örnek 3: 1’den 10’a kadar olan sayıları yazdıran programı yazınız.

for (int sayaç = 1; sayaç < 11; sayaç++)
{
Console.WriteLine(sayaç);
}
Console.ReadKey();

Örnek 4:Klavyeden girilen sayıya kadar olan sayıları yazdıran programı yazınız.
int sayı;
Console.Write("Bir Sayı Giriniz= ");
sayı =Convert.ToInt16(Console.ReadLine());
for (int sayaç = 1; sayaç < sayı+1; sayaç++)
{
Console.WriteLine(sayaç);
}
Console.ReadKey();

Örnek 5: Klavyeden girilen sayı kadar sayıyı yazan programı yazınız.
int sayı;
Console.Write("Bir Sayı Giriniz= ");
sayı =Convert.ToInt16(Console.ReadLine());
for (int sayaç = 1; sayaç < sayı+1; sayaç++)
{
Console.WriteLine(sayı);
}
Console.ReadKey();

Örnek 6:10’dan 100’e kadar olan sayıları onar onar artırarak yazan programı yazınız.
for (int sayaç = 10; sayaç < 101; sayaç+=10)
{
Console.WriteLine(sayaç);
}
Console.ReadKey();

Örnek 7: 100’den 10’a kadar olan sayıları onar onar azaltarak yazan programı yazınız.
for (int sayaç = 100; sayaç >9; sayaç-=10)
{
Console.WriteLine(sayaç);
}
Console.ReadKey();


Örnek 8:Klavyeden başlangıç, bitiş ve artış miktarı girilen sayıları yazdıran programı yazınız.
int baş, bitiş, artış;

Console.Write("Başlangıç Değeri = ");
baş = Convert.ToInt16(Console.ReadLine());

Console.Write("Bitiş Değeri = ");
bitiş = Convert.ToInt16(Console.ReadLine());

Console.Write("Artış Değeri = ");
artış = Convert.ToInt16(Console.ReadLine());

for (int sayaç = baş; sayaç

{
Console.WriteLine(sayaç);
}
Console.ReadKey();

Örnek 9: Klavyeden girilen 5 sayının toplamını, aritmetik ortalamasını bulan programı yazınız.

int sayı, toplam, ortalama;
toplam = 0;

for (int sayaç = 1; sayaç <6; sayaç++)
{
Console.Write(sayaç + ".Sayıyı Gir= ");
sayı = Convert.ToInt16(Console.ReadLine());
toplam = toplam + sayı;
}

ortalama = toplam / 5;
Console.WriteLine("Sayıların Toplamı = " + toplam);
Console.WriteLine("Sayıların Ortalaması = " + ortalama);
Console.ReadKey();

Örnek 10 : Klavyeden girilen sayının çarpım tablosunu hazırlayan programı yazınız.
int sayı;
Console.Write("Bir Sayı Gir = ");
sayı = Convert.ToInt16(Console.ReadLine());

for (int sayaç = 1; sayaç <11; sayaç++)
{
Console.WriteLine(sayaç + " * " + sayı + " = " + sayı * sayaç);
}
Console.ReadKey();

1 Mart 2012 Perşembe

Karışık İşlemler Menüsü 2

string seçim, sayı1, sayı2, dolarkuru, eurokuru, TL,
yazılı1, yazılı2, sözlü, ödev, boy, yaş, kilo, cinsiyet;

double toplam, fark, çarpım, bölüm, dolar, euro, ortalama, ideal;

menü:

Console.ForegroundColor = ConsoleColor.Blue;
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Clear();

Console.CursorLeft = 30; Console.CursorTop = 2;
Console.Write("KARIŞIK İŞLEMLER ANA MENÜSÜ");

Console.CursorLeft = 35; Console.CursorTop = 4;
Console.Write("1-DÖRT İŞLEM");

Console.CursorLeft = 35; Console.CursorTop = 5;
Console.Write("2-TL=>DOLAR-EURO");

Console.CursorLeft = 35; Console.CursorTop = 6;
Console.Write("3-NOT ORTALAMA");

Console.CursorLeft = 35; Console.CursorTop = 7;
Console.Write("4-İDEAL KİLO");

Console.CursorLeft = 35; Console.CursorTop = 8;
Console.Write("5-ÇIKIŞ");

Console.CursorLeft = 30; Console.CursorTop = 10;
Console.Write("SEÇİMİNİZ [1-5] = ");
seçim = Console.ReadLine();

if (seçim == "5") Environment.Exit(0);

if (seçim == "1")
{
//Dört İşlem Hesaplamaları Bölümü
Console.CursorLeft = 35; Console.CursorTop = 12;
Console.Write("1.Sayı = ");
sayı1 = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 14;
Console.Write("2.Sayı = ");
sayı2 = Console.ReadLine();

toplam = Convert.ToInt16(sayı1) + Convert.ToInt16(sayı2);
fark = Convert.ToInt16(sayı1) - Convert.ToInt16(sayı2);
çarpım = Convert.ToInt16(sayı1) * Convert.ToInt16(sayı2);
bölüm = Convert.ToInt16(sayı1) / Convert.ToInt16(sayı2);

Console.CursorLeft = 35; Console.CursorTop = 16;
Console.Write("Toplam = " + toplam);
Console.CursorLeft = 35; Console.CursorTop = 17;
Console.Write("Fark = " + fark);
Console.CursorLeft = 35; Console.CursorTop = 18;
Console.Write("Çarpım = " + çarpım);
Console.CursorLeft = 35; Console.CursorTop = 19;
Console.Write("Bölüm = " + bölüm);
}

if (seçim == "2")
{
//Döviz İşlem Hesaplamaları Bölümü
Console.CursorLeft = 35; Console.CursorTop = 12;
Console.Write("Dolar Kuru = ");
dolarkuru = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 13;
Console.Write("Euro Kuru = ");
eurokuru = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 14;
Console.Write("Türk Lirası = ");
TL = Console.ReadLine();

dolar = Convert.ToInt16(TL) / Convert.ToDouble(dolarkuru);
euro = Convert.ToInt16(TL) / Convert.ToDouble(eurokuru);

Console.CursorLeft = 35; Console.CursorTop = 16;
Console.Write("Dolar = " + dolar);
Console.CursorLeft = 35; Console.CursorTop = 17;
Console.Write("Euro = " + euro);
}

if (seçim == "3")
{
//Not İşlem Hesaplamaları Bölümü
Console.CursorLeft = 35; Console.CursorTop = 12;
Console.Write("1.Yazılı = ");
yazılı1 = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 13;
Console.Write("2.Yazılı = ");
yazılı2 = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 14;
Console.Write("Sözlü = ");
sözlü = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 15;
Console.Write("Ödev = ");
ödev = Console.ReadLine();

ortalama = (Convert.ToInt16(yazılı1) + Convert.ToInt16(yazılı2) +
Convert.ToInt16(sözlü) + Convert.ToInt16(ödev))/4;

Console.CursorLeft = 35; Console.CursorTop = 17;
Console.Write("Ortalama = " + ortalama);
if (ortalama < 45)
{
Console.CursorLeft = 35; Console.CursorTop = 18;
Console.Write("Sonuç = Kaldınız");
}
else
{
Console.CursorLeft = 35; Console.CursorTop = 18;
Console.Write("Sonuç = Geçtiniz");
}
}

if (seçim == "4")
{
//İdeal Kilo İşlem Hesaplamaları Bölümü
Console.CursorLeft = 35; Console.CursorTop = 12;
Console.Write("Boy = ");
boy = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 13;
Console.Write("Yaş = ");
yaş = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 14;
Console.Write("Kilo = ");
kilo = Console.ReadLine();
Console.CursorLeft = 35; Console.CursorTop = 15;
Console.Write("Cinsiyet = ");
cinsiyet = Console.ReadLine();

if((cinsiyet=="E") || (cinsiyet=="e"))
ideal = ((Convert.ToInt16(boy) -100 + Convert.ToInt16(yaş) /10))*0.9;
else
ideal = ((Convert.ToInt16(boy) -100 + Convert.ToInt16(yaş) /10))*0.8;

Console.CursorLeft = 35; Console.CursorTop = 17;
Console.Write("İdeal Kilo = " + ideal);

if (Convert.ToInt16(kilo) > ideal)
{
Console.CursorLeft = 35; Console.CursorTop = 18;
Console.Write("Sonuç = Şişmansınız");
}
if (Convert.ToInt16(kilo) < ideal)
{
Console.CursorLeft = 35; Console.CursorTop = 18;
Console.Write("Sonuç = Zayıfsınız");
}
if (Convert.ToInt16(kilo) == ideal)
{
Console.CursorLeft = 35; Console.CursorTop = 18;
Console.Write("Sonuç = İdealsiniz");
}
}

Console.CursorLeft = 30; Console.CursorTop = 20;
Console.Write("Ana Menüye Dönmek İçin Bir Tuşa Basınız ");

Console.ReadKey();

goto menü;
}
}
}

27 Şubat 2012 Pazartesi

Karışık İşlemler Menüsü

string seçim,kenar,kısa,uzun,yarıçap,dolar,dolarkuru;
double alan, çevre,TL;

menü:

Console.ForegroundColor = ConsoleColor.Blue;
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Clear();

Console.CursorLeft = 30; Console.CursorTop = 2;
Console.Write("KARIŞIK İŞLEM ANA MENÜSÜ");

Console.CursorLeft = 35; Console.CursorTop = 4;
Console.Write("1-KARE");

Console.CursorLeft = 35; Console.CursorTop = 5;
Console.Write("2-DİKDÖRTGEN");

Console.CursorLeft = 35; Console.CursorTop = 6;
Console.Write("3-DAİRE");

Console.CursorLeft = 35; Console.CursorTop = 7;
Console.Write("4-DOLAR-TL");

Console.CursorLeft = 35; Console.CursorTop = 8;
Console.Write("5-ÇIKIŞ");

Console.CursorLeft = 30; Console.CursorTop = 10;
Console.Write("SEÇİMİNİZ [1-5] = ");
seçim = Console.ReadLine();

if (seçim == "5") Environment.Exit(0);

if (seçim == "1")
{
//Kare Hesaplamaları Bölümü
Console.CursorLeft = 30; Console.CursorTop = 12;
Console.Write("Karenin Bir Kenarı = ");
kenar = Console.ReadLine();

alan = Convert.ToInt16(kenar) * Convert.ToInt16(kenar);
çevre = 4* Convert.ToInt16(kenar);

Console.CursorLeft = 30; Console.CursorTop = 14;
Console.Write("Karenin Alanı = " + alan);
Console.CursorLeft = 30; Console.CursorTop = 16;
Console.Write("Karenin Çevre = " + çevre);
}

if (seçim == "2")
{
//Dikdörtgen Hesaplamaları Bölümü
Console.CursorLeft = 30; Console.CursorTop = 12;
Console.Write("Dikdörtgenin Kısa Kenarı = ");
kısa = Console.ReadLine();
Console.CursorLeft = 30; Console.CursorTop = 13;
Console.Write("Dikdörtgenin Uzun Kenarı = ");
uzun = Console.ReadLine();

alan = Convert.ToInt16(kısa) * Convert.ToInt16(uzun);
çevre = 2 * (Convert.ToInt16(kısa) + Convert.ToInt16(uzun));

Console.CursorLeft = 30; Console.CursorTop = 15;
Console.Write("Dikdörtgenin Alanı = " + alan);
Console.CursorLeft = 30; Console.CursorTop = 17;
Console.Write("Dikdörtgenin Çevre = " + çevre);
}

if (seçim == "3")
{
//Daire Hesaplamaları Bölümü
Console.CursorLeft = 30; Console.CursorTop = 12;
Console.Write("Dairenin Yarıçapı = ");
yarıçap = Console.ReadLine();

alan = 3.14 * Convert.ToInt16(yarıçap) * Convert.ToInt16(yarıçap);
çevre = 2 * 3.14* Convert.ToInt16(yarıçap);

Console.CursorLeft = 30; Console.CursorTop = 14;
Console.Write("Dairenin Alanı = " + alan);
Console.CursorLeft = 30; Console.CursorTop = 16;
Console.Write("Dairenin Çevre = " + çevre);
}

if (seçim == "4")
{
//Dolar-TL Hesaplamaları Bölümü
Console.CursorLeft = 30; Console.CursorTop = 12;
Console.Write("Dolar Kuru = ");
dolarkuru = Console.ReadLine();
Console.CursorLeft = 30; Console.CursorTop = 13;
Console.Write("Dolar Miktarı = ");
dolar = Console.ReadLine();

TL = Convert.ToDouble(dolar) * Convert.ToDouble(dolarkuru);

Console.CursorLeft = 30; Console.CursorTop = 15;
Console.Write("Türk Lirası = " + TL);

}

Console.CursorLeft = 20; Console.CursorTop = 20;
Console.Write("Ana Menüden Yeni Seçim Yapmak İçin Bir Tuşa Basınız ");

Console.ReadKey();

goto menü;

13 Şubat 2012 Pazartesi

İdeal Kilo Programı

Klavyeden Boy, Yaş, Kilo ve Cinsiyeti girilen kişinin İdeal Kilosunu hesaplayan programı yazınız.

İdeal = (Boy – 100 + Yaş /10) *Katsayı

Katsayı erkekler için 0.9 kadınlar için 0.8 alınacaktır.

static void Main(string[] args)
{
string boy, yaş, kilo,cinsiyet;
double ideal, katsayı=0.9;

Console.Write("Boyunuzu Giriniz = "); boy = Console.ReadLine();
Console.Write("Yaşınızı Giriniz = "); yaş = Console.ReadLine();
Console.Write("Kilonuzu Giriniz = "); kilo = Console.ReadLine();
Console.Write("Cinsiyetinizi Giriniz [E/K]= "); cinsiyet = Console.ReadLine();

if ((cinsiyet=="E")&& (cinsiyet=="e")) katsayı=0.9;
if ((cinsiyet=="K")&& (cinsiyet=="k")) katsayı=0.8;

ideal=(Convert.ToInt16(boy)-100 + Convert.ToInt16(yaş) / 10) * katsayı;

Console.WriteLine("İdeal Kilonuz = " + ideal);

if ( Convert.ToInt16(kilo) > ideal) Console.WriteLine("Şişmansınız");
if ( Convert.ToInt16(kilo) < ideal) Console.WriteLine("Zayıfsınız");
if ( Convert.ToInt16(kilo) == ideal) Console.WriteLine("İdealsiniz");

Console.ReadKey();

}

Menülü Dört İşlem Yapan Program

Klavyeden girilen iki sayıyı kullanıcının isteğine göre dört işlemden birini uygulayan programı yazınız.

static void Main(string[] args)
{
string seçim, sayı1, sayı2;
int sonuç=1;

menü:

Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();

Console.CursorLeft = 30; Console.CursorTop = 2;
Console.Write("DÖRT İŞLEM ANA MENÜSÜ");

Console.CursorLeft = 35; Console.CursorTop = 4;
Console.Write("1-TOPLAMA");

Console.CursorLeft = 35; Console.CursorTop =5;
Console.Write("2-ÇIKARMA");

Console.CursorLeft = 35; Console.CursorTop = 6;
Console.Write("3-ÇARPMA");

Console.CursorLeft = 35; Console.CursorTop = 7;
Console.Write("4-BÖLME");

Console.CursorLeft = 35; Console.CursorTop = 8;
Console.Write("5-ÇIKIŞ");

Console.CursorLeft = 30; Console.CursorTop = 10;
Console.Write("SEÇİMİNİZ [1-5] = ");
seçim = Console.ReadLine();

if (seçim == "5") Environment.Exit(0);

Console.CursorLeft = 30; Console.CursorTop = 12;
Console.Write("1.Sayı = "); sayı1 = Console.ReadLine();

Console.CursorLeft = 30; Console.CursorTop = 13;
Console.Write("2.Sayı = "); sayı2 = Console.ReadLine();

if (seçim == "1")
sonuç = Convert.ToInt16(sayı1) + Convert.ToInt16(sayı2);

if (seçim == "2")
sonuç = Convert.ToInt16(sayı1) - Convert.ToInt16(sayı2);

if (seçim == "3")
sonuç = Convert.ToInt16(sayı1) * Convert.ToInt16(sayı2);

if (seçim == "4")
sonuç = Convert.ToInt16(sayı1) / Convert.ToInt16(sayı2);


Console.CursorLeft = 30; Console.CursorTop = 14;
Console.WriteLine("Sonuç = " + sonuç);

Console.CursorLeft = 20; Console.CursorTop = 16;
Console.Write("Ana Menüden Yeni Seçim Yapmak İçin Bir Tuşa Basınız ");

Console.ReadKey();

goto menü;

}

11 Ocak 2012 Çarşamba

Parça Prim Hesaplama

Parça Prim
0 - 10 10
11 - 20 20
21 Üstü 30

string parça;
int prim=0;

Console.Write("Parça Sayısı= ");
parça = Console.ReadLine();

if (Convert.ToInt16(parça) < 11)
prim = Convert.ToInt16(parça) * 10;
if ((Convert.ToInt16(parça) >10)&&(Convert.ToInt16(parça) <21))
prim= 100+ (Convert.ToInt16(parça) -10)*20;
if (Convert.ToInt16(parça) > 20)

prim = 300 + (Convert.ToInt16(parça)-20) * 30;

Console.WriteLine("Hak ettiğiniz prim = " + prim);

Console.ReadKey();

Ortalama, Geçti Kaldı ve Karne Notu

string yazılı1, yazılı2, sözlü;
int ortalama;


Console.Write("Birinci Yazılı= ");
yazılı1 = Console.ReadLine();
Console.Write("İkinci Yazılı= ");
yazılı2 = Console.ReadLine();
Console.Write("Sözlü Notu= ");
sözlü = Console.ReadLine();

ortalama = (Convert.ToInt16(yazılı1) + Convert.ToInt16(yazılı2) + Convert.ToInt16(sözlü)) / 3;

Console.WriteLine("Ortalamanz = " + ortalama);

if (ortalama < 45) Console.WriteLine("Sen Kaldn Yavrum");
if (ortalama >= 45) Console.WriteLine("Hadi Yine yisin Getin");
if (ortalama < 25) Console.WriteLine("Karne Notunuz = 0");

if ((ortalama > 24) && (ortalama <45))
Console.WriteLine("Karne Notunuz = 1");
if ((ortalama > 44) && (ortalama < 55))

Console.WriteLine("Karne Notunuz = 2");
if ((ortalama > 54) && (ortalama < 70))

Console.WriteLine("Karne Notunuz = 3");
if ((ortalama > 69) && (ortalama < 85))

Console.WriteLine("Karne Notunuz = 4");
if (ortalama > 84) Console.WriteLine("Karne Notunuz = 5");

Console.ReadKey();

Tek-Çift Negatif-Pozitif Program

string sayı;
int kalan;


Console.Write("Bir Sayı Giriniz = ");
sayı = Console.ReadLine();


kalan = Convert.ToInt16(sayı) % 2;

if (kalan == 0) Console.Write("Sayı Çift");
if (kalan == 1) Console.Write("Sayı Tek");

if (Convert.ToInt16(sayı) < 0) Console.Write("Sayı Negatif");

if (Convert.ToInt16(sayı) > 0) Console.Write("Sayı Pozitif");
if (Convert.ToInt16(sayı) == 0) Console.Write("Sayı Sıfırdır");

Console.ReadKey();

Kullanıcı Adı ve Şifre Kontrol Programı

string kullanıcı, şifre;

Console.Write("Kullanıcı Adını Giriniz = ");
kullanıcı = Console.ReadLine();

Console.Write("Şifreyi Giriniz = ");
şifre = Console.ReadLine();

if ((kullanıcı == "Demet") && (şifre == "1234"))
Console.WriteLine("Tebrikler Bildiniz");


if ((kullanıcı != "Demet") (şifre != "1234"))
Console.WriteLine("Üzgünüm Bilemediniz");

Console.ReadKey();