Skip to content

Instantly share code, notes, and snippets.

@austa
Created March 24, 2013 14:27
Show Gist options
  • Select an option

  • Save austa/5232165 to your computer and use it in GitHub Desktop.

Select an option

Save austa/5232165 to your computer and use it in GitHub Desktop.
/*
* File: main.c
* Author: alaattin
*
* Created on 24 Mart 2013 Pazar, 16:18
*/
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int faktoriyel(int);
int main(int argc, char** argv) {
int sonuc, sayi;
int (*fonkPtr) (int); // Prototip tanımlamaya benziyor.Sadece fonksiyon adı * ile birlikte parantez içinde.
fonkPtr = faktoriyel; // Fonksiyon adı aynı zamanda fonksiyonun adresini verir.
printf("sayı giriniz: \n");
scanf("%d", &sayi);
printf ("Sonucumuz: %d \n", sonuc = (*fonkPtr)(sayi));
return (EXIT_SUCCESS);
}
int faktoriyel(int sayi){
int sonuc = 1, i = 0;
if (sayi == 1 && sayi == 0) {
return sonuc;
}
else{
for(i = sayi; i > 0; i--){
sonuc *= i;
}
}
return sonuc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment