Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //factorial.h
- #ifndef L1P1_H
- #define L1P1_H
- #pragma once
- #include<iostream>
- using namespace std;
- int factIter(int n);
- int factRec(int n);
- #endif;
- //factorial.cpp
- #include"factorial.h"
- //Factorial Iterativ
- int factIter(int n)
- {
- int rez,i;
- for(i=1,rez=1;i<=n;i++)
- rez=rez*i;
- //rez*=i;
- return rez;
- }
- //Factorial Recursiv
- int factRec(int n)
- {
- if(n<=1)
- return 1;
- else
- return n*
- factRec(n-1);
- }
- //main.cpp
- #include"factorial.h"
- int main()
- {
- int f1,f2,n;
- do
- {
- cout<<"n=";
- cin>>n;
- }while(n<0);
- f1=factIter(n);
- f2=factRec(n);
- cout<<n<<"!="<<f1<<"="<<f2<<endl;
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment