Hello everyone,
I have an assignment due on Tuesday. I’ve been working on in, but I can’t get the last part of it, which is the last function. Here I am posting the assignment and what I have done, so far.
********* ASSIGNMENT **********
Create a project called Daily7. Add a C source file to the project named daily7.c. Write a program that will prompt the user to enter a positive integer. Your program should then call a function that you write called recursive_down_to_zero that takes one argument of type integer and will use recursion as we did in class to print all of the integers from the number entered down to and including the number zero with each number appearing on one line.
Next you should print one line containing four asterisks and a new line.
Finally your program should call another function that you write called recursive_up_to_int that takes one argument of type integer and will use recursion as we did in class to print all of the integers from zero up to and including the number entered from the keyboard.
Please note that you may NOT use a loop in this program, you must use recursion.
End of assignment*
Here is what I got so far. I was able to print the first part, which is counting down to zero. But when it gets to count up, I got stuck.
#include <stdio.h>
//Functions prototype.
void recursive_down_to_zero(int);
void recursive_up_to_int(int);
int main( int argc , char* argv )
{
int number;
printf("Enter a positive interger: ");
scanf("%d", &number);
recursive_down_to_zero(number); //Call recursive down to zero.
printf("****\n"); //Prints the asterisk between the two functions
recursive_up_to_int(number); //Call recursive up to int.
return 0;
}
void recursive_down_to_zero( int num )
{
int number;
if (num >= 0)
{
printf("%d\n", num);
recursive_down_to_zero(num - 1);
}
}
void recurisve_up_to_int( int num )
{
if (num <= num)
{
printf("%d\n", num);
num = 0;
recursive_up_to_int(num + 1);
}
}
Anything can help, thank you in advance!