Bu örnekte 1-100 arası rastgele üretilen sayılardan tek sayıların ortalamasını hesaplayıp ekrana yazdıracağız.
Örneğe başlamadan önce C# Rastgele Sayı Üretme sayfasını ziyaret edebilirsiniz.
namespace _35.RastgeleOrnek4
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
int sayi = 0, toplam = 0, sayac = 0;
for (int i = 1; i <= 10; i++)
{
sayi = random.Next(1, 100);
Console.WriteLine(i + ". sayi = " + sayi);
if (sayi % 2 == 1)
{
toplam += sayi;
sayac++;
// tek sayi adedini tutar..
}
}
Console.WriteLine("Tek sayilarin ortalamasi = " + (toplam / sayac));
Console.ReadLine();
}
}
}
C# dilinde rastgele sayı üretmek için Random sınıfını kullanıyoruz. Bu sınıftan bir tane nesne oluşturup bu nesne ile istediğimiz aralıklarda rastgele sayılar üretiyoruz.
Sayıları üretirken, üretilen sayının tek sayı olup olmadığını kontrol ediyoruz. (Detaylı anlatım için C# Tek-Çift Sayı Bulma sayfasını inceleyebilirsiniz.)
Eğer üretilen sayı tek sayı ise sayıları topluyoruz ve “sayac” değişkenini artırıyoruz. Bu şekilde döngünün sonunda tek sayıların toplamını ve kaç adet olduğunu bulacağız.
En son olarak da toplam değişkenini sayac değişkenine bölerek tek sayıların ortalamasını bulmuş oluyoruz.
Kodun ekran çıktısı şu şekildedir:


54 Yorum
… [Trackback]
[…] There you will find 42990 more Info to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Info to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More here on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More Information here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More Information here on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Info on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Information to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More Information here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More Information here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Here you will find 79022 more Info to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
… [Trackback]
[…] Read More Information here on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Info on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Info to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More Information here on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] There you will find 65545 more Information on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
Maybe Dogecoin is a giant inside joke, and I’m just not in on it. Maybe Dogecoin really is headed to the moon on a crypto rocket ship (both literally and metaphorically). And maybe Musk is such an incredible genius that I just can’t possibly understand what he plans to do with Dogecoin. Dogecoin is different from bitcoin and many other cryptocurrencies in a few key ways. For one thing, there isn’t a finite cap on the number of dogecoins that can be produced. Bitcoin does have such a cap, and its relative scarcity plays a role in its widespread use as a speculative investment. Here’s Why Dogecoin’s (DOGE) Price Can Hit $10 In the Bull Run Not only do I think this crypto will never reach $1, but I wouldn’t invest my hard-earned savings in it at all. In fact, I suspect this token has a better shot at going to zero first. There’s a much better option for investors to choose.
https://milkyway.cs.rpi.edu/milkyway/show_user.php?userid=8024371
Select from 3,000+ Gift Cards and buy them with cryptocurrencies via CoinGate, Binance Pay, or using VISA MasterCard. To verify your card, a small amount of $0.10 SGD (or local equivalent) will be temporarily held for up to 7 days and won’t be charged – please confirm this transaction in order to complete the process. Credit cards come with greater security protections compared to debit cards. It’s best to do your due diligence to research the history and reputation of the exchange, as this is where the transacting will take place (if your bank allows crypto payments). Choosing to buy Bitcoin with a credit card or a debit card is a fast and secure way to acquire some of the most popular cryptocurrency on the market. However, no matter how you choose to perform Bitcoin-related transactions, you can be sure that you’ll receive your BTC in minutes, and that, thanks to the blockchain technology, your transactions will be completely secure and private.
… [Trackback]
[…] Read More on to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More Info here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Info on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Here you will find 94023 more Info to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More Information here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Here you will find 55397 more Information on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More here on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
I’m extremely impressed together with your writing abilities as well as with the layout for your blog. Is that this a paid subject matter or did you modify it your self? Either way keep up the nice high quality writing, it is uncommon to peer a great weblog like this one today!
… [Trackback]
[…] There you can find 92119 additional Info on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
kamagra livraison 24h: kamagra 100mg prix – acheter kamagra site fiable
… [Trackback]
[…] Find More Info here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More on on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Information to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Information to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Info on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More Info here to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] There you will find 68889 additional Info to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More on on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More on to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More on to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More Info here on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Read More on on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] There you can find 129 more Info on that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
… [Trackback]
[…] Find More on to that Topic: kodbloklari.com/csharp-rastgele-sayilarla-ornek-4/ […]
เป็นข้อมูลที่มีประโยชน์มากเรื่อง “ดอกไม้งานศพ” บอกถึงวิธีเลือก ดอกไม้
ได้อย่างถูกต้อง มากขึ้น ค่ะ
Here is my homepage … จัดดอกไม้งานศพ
บทความนี้ให้ข้อมูลมีประโยชน์มากครับ ถ้าใครกำลังมองหาบริการจัดดอกไม้งานศพ ผมแนะนำลองดูร้านที่มีผลงานจริงและรีวิวดี ๆ ครับ
Here is my site – รับจัดดอกไม้งานศพ
Nice blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would really make
my blog shine. Please let me know where you got your theme.
Thanks a lot
Here is my web blog – รับออกแบบโลโก้ ตามหลักฮวงจุ้ย
Write more, thats all I have to say. Literally, it seems as though you relied onn the video to
make your point. You obviously know wat youre talking about, why throw away your intelligence on just posting videos to yokur weblog when you could be giving uss something informative
to read?
Here is my web site: ฮวงจุ้ยโลโก้
ชอบแนวคิดที่แชร์ไว้ในบทความนี้ครับ ถ้าใครกำลังมองหาร้านจัดดอกไม้งานศพ ผมแนะนำลองดูร้านที่มีผลงานจริงและรีวิวดี ๆ ครับ
Here is my blog post … Mikki
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.