예제 #1
0
파일: nthf.c 프로젝트: deepw/FirstRepo
int main () 
{
	int n = 20;
	printf ("nth fibo = %d.\n", fibo(n));
	printf ("nth fibo = %d.\n", fibo_rec(n));
	return 0;
}
예제 #2
0
int main(const int argc, const char* const argv[]) {

  if (Environment::version_output(std::cout, proginfo, argc, argv)) return 0;

  const Argument_t N = (argc > 1) ? std::stoul(argv[1]) : default_N;
  const Result_t F = fibo_direct(N);
  const RecMode recmode = (argc > 2) ? to_RecMode(argv[2]) : default_recmode;

  if (recmode == RecMode::nonrec) {
    std::cout << F << "\n";
    return 0;
  }

  else if (recmode == RecMode::nonpar) {
    const Result_t F2 = fibo_rec0(N);
    if (F != F2) {
      std::cerr << "Error: Recursive result (non-parallel) is " << F2 << ", but should be " << F << "\n";
      return code(Error::nonpar);
    }
    std::cout << N << "\n";
    return 0;
  }

  else {
    assert(recmode == RecMode::par);
    const Argument_t max_depth = (argc > 3) ? std::stoul(argv[3]) : depth(std::thread::hardware_concurrency());
    const Result_t F2 = fibo_rec(N, max_depth);
    if (F != F2) {
      std::cerr << "Error: Recursive result (parallel) is " << F2 << ", but should be " << F << "\n";
      return code(Error::par);
    }
    std::cout << N << " " << max_depth << "\n";
  }
}
예제 #3
0
파일: nthf.c 프로젝트: deepw/FirstRepo
int fibo_rec(int n)
{
	if (n==0 || n==1)
		return 1;
	return (fibo_rec(n-1) + fibo_rec(n-2));
}
예제 #4
0
파일: uppg2.c 프로젝트: slaeshjag/algdata
int fibo_rec(int prev, int sum, int i, int max) {
	if (i == max)
		return sum;
	return fibo_rec(sum, prev + sum, i + 1, max);
}