Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:01:31+00:00 2026-05-30T20:01:31+00:00

while practicing recursive functions, I have written this code for fibonacci series and (factorial)

  • 0

while practicing recursive functions, I have written this code for fibonacci series and (factorial) the program does not run and shows the error “Control reaches end of non-void function” i suspect this is about the last iteration reaching zero and not knowing what to do into minus integers. I have tried return 0, return 1, but no good. any suggestions?

#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <ctime>
using namespace std;

int fib(int n) {
    int x;
        if(n<=1) {
            cout << "zero reached \n";
            x= 1;
        } else {
            x= fib(n-1)+fib(n-2);
            return x;
        }
    }




int factorial(int n){
    int x;
    if (n==0){
        x=1;
       }
    else {
            x=(n*factorial(n-1));
            return x;
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:01:32+00:00Added an answer on May 30, 2026 at 8:01 pm

    Presumably the factorial function should be returning n * factorial(n-1) for n > 0.

    x=(factorial(n)*factorial(n-1)) should read x = n * factorial(n-1)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While practicing a tutorial on GTK+ I have encountered sample code that looks like
While I do a program, sometimes I've got this doubt. I have been using
I am new to Javascript. while practicing i encounter a code regarding event handling.
I am practicing these problems: http://code.google.com/codejam/contest/32016/dashboard#s=p1&a=1 I believe I have the correct solution, (even
I am practicing how to find and remove dead code. I have the following
While working with some jQuery ajax, I've run into this problem with Chrome and
I'm not looking to copy a qsort algorithm. I'm practicing writing qsort and this
When I run the following code, I get an error. package practicing.io; import java.io.FileInputStream;
I am practicing regex with C#. This is my code: string test = this
I have been practicing DDD for a while now with the 4 distinct layers:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.