553 views
0 votes
0 votes

void PrintNumber(unsigned int N)
{
printf("%u\t", N);
}
void PrintValue (unsigned int N) 
{
if (N>=10)
{
PrintValue(N/10);
}
PrintNumber(N%10);
}

int main()
{
PrintValue(1234);
return 0;
}

The output of the above program is:
image:o9.PNG

  1.   2 & 4
  2.   2 & 3
  3.   1 & 3
     
  4.   1 & 4

How to choose between Option 3 and 4? 

2 Answers

Best answer
1 votes
1 votes

If you observe carefully. Value of N passed changes like

N --->N/10 --->N/102 ---> N/103 --- and so on.

you can build a recursive function  

 

for the above function There is no meaning in deciding 0 < N < 10 as base condition because if N = 0 if condition fails T(N/10) = 0/10 = 0 which again calls T(N/10) = 0/10 = 0 and so on. Therefore we want to stop further execution once zero has occurred therefore we put zero in base condition.

Happy learning :)  

selected by
0 votes
0 votes
1 and 3 is correct because the recursion should stop when n is zero.

Related questions

0 votes
0 votes
0 answers
2
srestha asked Mar 7, 2018
612 views
#include<stdio.h int fun1(int x) { x=14; } int fun2(int x) { x=20; } int main() { int(*p)(),m,n; scanf("%d",&m); if(m) p=fun1; else p=fun2; n=(*p)(); printf("%d",n); retu...
0 votes
0 votes
0 answers
3
srestha asked Mar 6, 2018
407 views
#include<stdio.h int main() { char a[]={'A','B','C','D'}; char *p=&a[0]; *p++; printf("%c%c",*++p, *p); }What will be the output?1)C B2)B B3)B A4)C A
0 votes
0 votes
0 answers
4
Parshu gate asked Dec 5, 2017
500 views