" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
w C++ będzie tak :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
double silnia(int x);
main()
{
system("CLS");
int n;
cout<<"\n\nn=";
cin>>n;
cout<<"\n\n\t"<<n<<"!="<<silnia(n);
cout<<"\n\n";
system ("pause");
}
//////////////// funkcja/////////
double silnia(int x)
{
double i,q;
if((x==0)||(x==1))
q=1;
else
{
q=1;
for (i=2;i<=x;i++)
{
q=q*i;
}
}
return q;
}
a w turbo pascalu tak :
program silnia;
uses crt;
var
n,i:integer;
{/PROCEDURA/}
function sil(x:integer):real;
var
i:integer;
q:real;
begin
if(x=0) or (x=1) then
q:=1
else
begin
q:=1;
for i:=2 to x do
q:=q*i
end;
sil:=q;
end;