Need help with a assignment! Using C.

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!

For printing down to zero, you first print the number, and then process the recursion.
For printing up to number, you first process the recursion, and then print the number.

Here’s why: Basically, you want to print num inside any call ‘function(num)’. For recursion up to num, you still want to do the printing there. But, you want all other numbers printed before printing num. (i.e., smaller numbers should be processed before current number should be processed.) Which means you recurse first and then print.

That should help. Try it out, and let me know.
All the best. And congrats on getting the rest of the program working.

1 Like

Thank you a lot! I did it and submitted on time! You comment really helped me to figure out where I was suppose to print.

1 Like