In C++

Write a recursive function that does the following:

Given a number that could be up to 10 digits long, place the commas in the appropriate

places.

For example the number 1087045 would be displayed as

1,087,045

Do not use the static modifier. No global variables.

The input has to be in number format.

Example: non-tail

c(1087045)=045 , c(1087) on the way back display , and 045

c(1087)=087 , c(1) on the way back display , and 087

c(1)= 1

display 1

Respuesta :

Answer:

#include<iostream>

using namespace std;

void c(long int n)

{

  static int i=0;  

  if(n==0)

  return ;

  i++;

  c(n/10);//recursive call

  //printing after recursive call

  cout<<n%10;

  i--;

  if(i%3==0 && i!=0)

  cout<<",";

  if(i==0)

  cout<<endl;

}

int main()

{

  c(1087045);

  cout<<endl;

 

  return 0;

 

}#include<iostream>

using namespace std;

void c(long int n)

{

  static int i=0;  

  if(n==0)

  return ;

  i++;

  c(n/10);//recursive call

  //printing after recursive call

  cout<<n%10;

  i--;

  if(i%3==0 && i!=0)

  cout<<",";

  if(i==0)

  cout<<endl;

}

int main()

{

  c(1087045);

  cout<<endl;

 

  return 0;

 

}

output:

1,087,045

Process exited normally.

Press any key to continue . . .

 

//PLS give a thumbs up if you find this helpful, it helps me alot, thanks.

Explanation:

ACCESS MORE
EDU ACCESS
Universidad de Mexico