huuuge problem with a recursion

Hi, I had to make a program using recursion.It works like this - when you type a number , it returns an array which consist of the number's digits. I have an idea for the algorythm but I can't make the code. That's what I came up with...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 #include<iostream.h>
#include<string.h>
#include<stdlib.h>

const int N=20;


int part[N]; //array with digits
 
int counting(int a=0, int part[], char chislo);

int main(int part[], char chislo)
{

	cout<<"Input number..."<<endl;
	cin>>chislo;  

	counting(int a=0, int part[]);

	for(int i=0; i< chislo.length(); i++)
	{
		cout<<"Element No "<<i+1<<" is"<<part[i]<<endl;
	}

	

}

int counting(int a=0,int part[])
{   



	if (a==(chislo.length())) return 0;

	else
	{
	   part[a]=atoi(chislo[a]);  //turning the char into int
	   return(a+1, part[a+1]);

	}
}
I know it looks bad but that's what I managed to do , if you can correct it pls do
Last edited on
I`m not sure what you're doing here. Recursion involves amoungst other things the calling of the function from within that function. You appear to have declared two functions: counting() and zapis(). However I can`t see where you have called either from within either (respectively).
i.e. counting() from within counting() or zapis() from within zapis()
where is recursion going on here.. is it hidden?? :D
:D ...that's the problem... I know how to make the code for this program without recursion...but I can't make it using recursion and that's why it looks so bad. The idea is to use the second function for separating the digits (int counting) and it has to call itself.
Last edited on
hehehe..

i wonder if this program will even compile!!
is it compiling??
sorry, i am not able to understand what the program is trying to do..



Topic archived. No new replies allowed.