2 Ocak 2014 Perşembe

C Konsol Tekrarlamalı Faktöriyel Hesaplama - iterative faktöriyel hesaplama

KONU : C Konsol Uygulamalar - iterative faktöriyel hesaplama, tekrarlamalı faktöriyel hesaplama.
ETİKETLER: c faktöriyel hesaplama - c iterative faktöriyel hesaplama - c tekrarlamalı faktöriyel hesaplama - c döngüler - c konsol okuma - c konsol yazdırma.


#include < stdio.h >

int faktoriyel(int sayi);

int main()
{
 int sayi;
 
 int sonuc=0;
 
 printf( "Pozitif bir tam sayı giriniz: ");
 
 scanf("%d", &sayi);
 
 while(sayi < 0)
 {
  printf("Girilen tam sayı pozitif olmalıdır !! \n");
  printf( "Pozitif bir tam sayı giriniz: ");
  scanf("%d", &sayi);
 }
 
 // Girilen değer pozitif ise bu değeri sonuç yaz ve konsola yaz
 
 sonuc = faktoriyel(sayi);//faktoriyel iterative olarak hesaplayan metod sonucu
 
 printf("factorial(%d) = %ld \n",sayi,sonuc);

 //konsol ekranında sonucu görmek için bir karakter girilene kadar bekle
 
 scanf("%d",&sayi);
}

int faktoriyel(int sayi)
{
 int sonuc=1;
 
 //faktoriyeli iterative olarak hesaplayan metod
 
 for(int i=sayi;i > 0;i--)
 {
  sonuc = sonuc * i;
 }

 return sonuc;
 
}
   

Hiç yorum yok:

Yorum Gönder

Hatalı linkleri yorum yazarak bildirin

Etiketler

Array (9) bool (3) break (1) BubbleSort (1) C (23) char (4) Char Sınıfı (1) conio.h (5) Console (4) Dizi (1) Diziler (11) Döngüler (24) File Sınıfı (1) Fonksiyon (3) For (12) Function (2) Game (1) Getch (1) gets (1) if-else (6) if-else örnekleri (15) int (8) Konsol (16) Konsol Okuma (16) Konsol Yazdırma (17) Matematik (14) Oyun (1) Pointer (2) printf (9) scanf (8) Sort (1) stdio.h (10) stdlib.h (8) strcpy (1) String (1) string.h (2) Swap (1) Switch Case (3) time.h (1) while (5)