Banners Banners Banners Banners

Search

Senin, 07 Januari 2013

Program Menghitung Faktorial dengan Fungsi


Bahasa : C
Program : Borland C++ 5.02
Tentang : Function


Soal :

Buatlah Fungsi untuk menghitung nilai faktorial suatu bilangan yang ditentukan oleh user.

Jawab :

#include <conio.h>
#include <stdio.h>
int faktorial (int n);
int main()
{
int n,fak;
printf("berapa faktorial? ");scanf("%d",&n);
fak = faktorial(n);
printf("%d faktorial = %d\n",n,fak);
getch();
}
int faktorial (int n)
{
int i,f=1;
if(n<=0)
return(0);
for (i=2;i<=n;i++) f*=i;
return(f);
}




Silahkan Tinggalkan komentar anda berupa  pertanyaan, kritik, maupun saran. 

Created By : Rahmat H Slamet.

-- Info Seputar Teknologi dan Informasi  --


1 komentar:

nice for content because help me in homework thank you because with this post my task completed I am very grateful I hope that the next post will be better again I really liked your post !

Posting Komentar

Another Posts