C# Console Bir sayının herhangi bir dereceden kuvvetini bulma

{{ page.title }}

Algoritma

  1. Başla
  2. sayi,us,top = 1 değişkenlerini al
  3. sayi,us değerini gir
  4. top = top * sayi işlemini yap
  5. us değerini azalt
  6. Eğer us > 0 ise 4’e git, değilse devam et
  7. Yazdır top
  8. Bitir

Bu soruda program dili ile kullandığımız (^) işareti ya da hazır konksiyonları kullanılmamıştır. Girilen sayının us değerine göre aldığı sonuç hesaplanmıştır. Burada ayaç olarak us değişkeni kullanılmıştır. Azalma içinise “–” ifadesi kullanılmıştır.

Kod Yapısı

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dmg
{
class Program
{
static void Main(string[] args)
{
int sayi;
int us,
int top = 1;
Console.WriteLine("Sayıyı giriniz = ");
sayi = Convert.ToInt32( Console.ReadLine() );
Console.WriteLine("Ussu giriniz = ");
us = Convert.ToInt32( Console.ReadLine() );
while ( us > 0 )
{
top = top * sayi;
us--;
}
Console.WriteLine("Sonuç = " + top);
Console.ReadKey();
}
}
}

BOT Benson Topluluk kurucusu ve bir yazılımcı.