Trying to output this: \"Please enter a positive integer: 10 10 9 8 7 6 5 4 3 2
ID: 669432 • Letter: T
Question
Trying to output this:
"Please enter a positive integer: 10
10
9
8
7
6
5
4
3
2
1
0
****
1
2
3
4
5
6
7
8
9
10"
Trying to output this using recursion. This is what I have so far:
#include <stdio.h>
void recursive_down_to_zero();
int main(int argc, char * argv[]);
{
int input1;
input1 = 10
printf("Please enter a positive integer: %d", input1);
recursive_down_to_zero(input1-1);
return 0;
}
void recursive_down_to_zero()
{
if (input1 = 0)
printf("**** ")
recursive_down_to_zero(input1 + 1)
return 0;
}
Explanation / Answer
#include <stdio.h>
void recursive_down_to_zero();
int main(int argc, char * argv[]);
{
int input1;
input1 = 10
printf("Please enter a positive integer: %d", input1);
int decreasing = 1;
recursive_down_to_zero(input1, decreasing,max);
return 0;
}
void recursive_down_to_zero(int val, int order, int max)
{
if( val > max) return;
printf("%d ", val);
if (val == 0)
{ printf("**** "); order = 0;}
if( order == 1)
recursive_down_to_zero(val-1,1);
else
recursive_down_to_zero(val+1,0);
return ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.