Klavyeden girilen bir sayıya kadar tek sayıların ve çift sayıların toplamını bulan C# kodu


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication29
{
    class Program
    {
        static void Main(string[] args)
        {
       
            Console.Write("Lütfen Sayı Sınırınızı Giriniz : ");
            int sayi = int.Parse(Console.ReadLine());
            int tektoplam = 0;
            int cifttoplam = 0;
            for(int dongu = 0; dongu <=sayi ; dongu++)
            {
                if (dongu % 2 == 0)
                    cifttoplam = cifttoplam + dongu;
                 
                else
                    tektoplam = tektoplam + dongu;


            }
            Console.WriteLine(sayi + " sayısına kadar olan çift sayıların toplamı : " + cifttoplam);
            Console.WriteLine(sayi + " sayısına kadar olan tek sayıların toplamı : " + tektoplam);
            Console.ReadKey();
        }
    }
}

Hiç yorum yok:

Yorum Gönder