Jump to content

C# Ta Pozitif Değerli Değişkenleri Toplama


TuTaMixx
 Share

Recommended Posts

merhaba arkadaşlar bende 4 adet değişken var ve bu 4 değişkenin +1 -1 ve 0 gibi değerleri var.benim istediğim bu 4 değişkenden pozitif olanları ayrı toplayıp negatif olanları ayrı toplayıp ayrı ayrı labellara yazdırmak ancak bir türlü beceremedim yani 1.değişken değeri = +1 2.değişken değeri = -1 , 3. değişken değeri = 0, 4. değişken değeri= +1 ise label1 e +2 yazıp label 2 de -1 yazıp 0 içinde hiç birşey yapmaması lazım bunun kodlaması nasıldır ? şimdiden teşekkürler.
Link to comment
Share on other sites

[b]degiskenleri degisken[n] dizisinde tutalim.[/b]

[code]for(int i=0;i<degiskensayisi;i++)
if(degisken[i]<0)
negatif+=degisken[i]
if(degisken[i]>0)
pozitif+=degisken[i]

label1.Text=negatif
label2.Text=pozitif[/code]

Kodları kabaca yazdım, anlamadıysan daha detaylandırayım.

Link to comment
Share on other sites

benim şimdi 4 tane değişken var
durum0,durum1,durum2,durum3

bu değişkenlere göre kodu yazıp verebilirmisin bu değişkenlerin değerleri programın içinde belli.yani kullanıcı girmeyecek.

Link to comment
Share on other sites

[quote name='600' date='11 March 2012 - 22:06 ' timestamp='1331496392' post='1168070']
int sayi= Convert.ToInt32(textBox1.Text);

if (sayi > 0)
{
MessageBox.Show("Pozitif.");
}
else if (sayi < 0)
{
MessageBox.Show("Negatif.");

}
[/quote]

senin yaptığın çok ayrı birşey . benim istediğim değişkenlerde pozitif olanları ayrı bir yerde toplayıp ve negatifleride ayrı bir yerde toplayıp ayrı ayrı labellara yazdırmak.

Link to comment
Share on other sites

[quote name='TuTaMixx' date='11 March 2012 - 20:12 ' timestamp='1331496773' post='1168075']
benim şimdi 4 tane değişken var
durum0,durum1,durum2,durum3

bu değişkenlere göre kodu yazıp verebilirmisin bu değişkenlerin değerleri programın içinde belli.yani kullanıcı girmeyecek.
[/quote]

istersen teamviewer ile 1 dakikada halledeyim, şimdi bütün kodları buradan yazmayayım.

Link to comment
Share on other sites

int pozitiftoplam =0;
int negatiftoplam =0;
if(durum0 > 0)
{
pozifittoplam = pozitiftoplam +durum0;
}
if(durum0<0)
{
negatiftoplam = negatiftoplam + durum0;
}

if(durum1 > 0)
{
pozifittoplam = pozitiftoplam +durum1;
}
if(durum1<0)
{
negatiftoplam = negatiftoplam + durum1;
}

if(durum2 > 0)
{
pozifittoplam = pozitiftoplam +durum2;
}
if(durum2<0)
{
negatiftoplam = negatiftoplam + durum2;
}

if(durum3 > 0)
{
pozifittoplam = pozitiftoplam +durum3;
}
if(durum3<0)
{
negatiftoplam = negatiftoplam + durum3;
}

label1.Text="Pozitif Toplamlar: " + pozitiftoplam;
label2.Text = "Negatif Toplamlar: " + negatiftoplam;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...