kawkaa37
Hectopat
- Katılım
- 1 Temmuz 2021
- Mesajlar
- 74
- Çözümler
- 1
Daha fazla
- Cinsiyet
- Erkek
C#:
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
Console.Write("bir sayı giriniz: ");
int girilen_sayi = Convert.ToInt32(Console.ReadLine());
for (int i = 1; girilen_sayi >= i;i++)
{
if (girilen_sayi % 2 == 0)
{
Console.WriteLine("sayınız çift: ");
girilen_sayi = girilen_sayi / 2;
Console.WriteLine(girilen_sayi);
}
else if (girilen_sayi % 2 != 0)
{
Console.WriteLine("sayınız tek: ");
girilen_sayi = (girilen_sayi * 3) + 1;
Console.WriteLine(girilen_sayi);
}
}
}
}
}
Aynı sorunu yaşayanlar olursa:Bu kodda çalıştırınca en düşük 1 vermesi lazım fakat "girilen_sayi" değişkenine 12 verdiğimde en düşük 4 olarak verdi sorunu 1 saattir arıyorum bulamadım.C#:using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Blue; Console.Clear(); Console.Write("bir sayı giriniz: "); int girilen_sayi = Convert.ToInt32(Console.ReadLine()); for (int i = 1; girilen_sayi >= i;i++) { if (girilen_sayi % 2 == 0) { Console.WriteLine("sayınız çift: "); girilen_sayi = girilen_sayi / 2; Console.WriteLine(girilen_sayi); } else if (girilen_sayi % 2 != 0) { Console.WriteLine("sayınız tek: "); girilen_sayi = (girilen_sayi * 3) + 1; Console.WriteLine(girilen_sayi); } } } } }
C#:
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
Console.Write("bir sayı giriniz: ");
int girilen_sayi = Convert.ToInt32(Console.ReadLine());
while (girilen_sayi > 1)
{
if (girilen_sayi % 2 == 0)
{
Console.WriteLine("sayınız çift: ");
girilen_sayi = girilen_sayi / 2;
Console.WriteLine(girilen_sayi);
}
else
{
Console.WriteLine("sayınız tek: ");
girilen_sayi = (girilen_sayi * 3) + 1;
Console.WriteLine(girilen_sayi);
}
}
}
}
}
Son düzenleme: