Answer to Question #332725 in C for joe

Question #332725

Slowly But Surely

by CodeChum Admin

In life, good things take time.


Let's make a simple program that mirrors this beautiful idea where we ask the user for two integer inputs. The first one would represent the starting number and the second one would represent the next n integers after it.


For example, if the first number inputted is 2 and the second number inputted is 3, then the output would be 3, 4, 5 because these are the next 3 integers after 2.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for two integers and calls the slowDisplay() function.
  2. This slowDisplay() function is a recursive function which should perform the functionality explained in the problem description above.
  3. This function is only partially implemented as it lacks a base case. Your task is to add the base case needed by this recursive function.


Input


1. Starting integer

2. Number of integers

Output


Enter·starting·integer:·2
Enter·how·many·next·integers:·3
3·4·5




1
Expert's answer
2022-04-23T03:21:52-0400
#include <stdio.h>

void slowDisplay(int start, int cnt) {
    if(cnt == 0)
        return;
    else
    {
        printf("%d ", ++start);
        slowDisplay(start, (cnt-1));
    }
}

int main()
{
    int start, num;
    printf("Enter starting integer: ");
    scanf("%d", &start);
    printf("Enter how many next integers: ");
    scanf("%d", &num);
    slowDisplay(start, num);
    
    getchar();
    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS