450 views
0 votes
0 votes

#define LIMIT 1000

void fun2(int n)

{

  if (n <= 0)

     return;

  if (n > LIMIT)

    return;

  printf("%d ", n);

  fun2(2*n);

  printf("%d ", n);

}  

Will it be non terinating recursion if n is negative,if so then why?

1 Answer

0 votes
0 votes
If you pass any value less then equals to 0 then it will terminate in the starting condition if( n <= 0 ) return as well as it terminates for value larger then limit (i.e 1000 ).

Related questions

3 votes
3 votes
3 answers
1
Laxman Ghanchi asked May 19, 2023
1,113 views
#include<stdio.h void print(int n) { printf("Hello "); if(n++ == 0) return ; print(n); n++; } int main() { void print(); print(-4); }How many times printf execute?? And H...
0 votes
0 votes
1 answer
2
Laxman Ghanchi asked May 19, 2023
657 views
#include<stdio.h>void print(int n){ printf("Hello "); if(n++ == 0) return ; print(n); n++;}int main(){ void print(); print(-4);}
1 votes
1 votes
0 answers
4