I'm trying to write a program which take in a string of numbers and counts up the number of times the digits 1-9 appear and the does this again with the nes string.
So for example, if the starting value was 12312
this would be two 1, two 2, one 3
which becomes 212213
But i have become a little suck and not sure what i'm doing wrong! Would really apprecaite any help!!
Heres my code:
Expand|Select|Wrap|Line Numbers
- #include <math.h>
- #include <stdio.h>
- int i[100000],f[100000];
- int convert(int);
- int base = 10;
- int j,rept1, rept, x = 1, r,q,digits,n,count,p,m,s,l,con;
- main()
- {
- for(n=0;n<100000;n++)
- {
- i[n] = 0;
- f[n] = 0;
- }
- printf("Enter a number between 1 and 9: ");
- scanf("%d",&r);
- convert(r);
- printf("How many times do you want to run Conway's Sequence? ");
- scanf("%d",&rept1);
- q=0;
- for(j=0;j<x;j++)
- {
- printf("%d",i[j]);
- q++;
- }
- digits = q;
- printf("\n");
- for(count = 0; count<rept1; count++)
- {
- p=0;
- m=0;
- s=0;
- for(x=1;x<=9;x++)
- {
- while(m<=digits)
- {
- if(i[m]==x)
- {
- s++;
- }
- f[p] = s;
- f[p+1] = x;
- p += 2;
- m++;
- }
- }
- for(l=1; f[l]>0; l++)
- {
- printf("%d",f[l]);
- }
- printf("\n");
- }
- for(con=0;con<100000;con++)
- {
- i[con] = f[con];
- }
- }
- int convert(int r)
- {
- while(r>=pow((base),x))
- {
- x=x+1;
- }
- if(r>=base)
- {
- i[0] = r/base;
- i[1] = r%base;
- if(i[0]>=base)
- {
- i[x-rept-1] = i[1];
- r = i[0];
- rept = rept+1;
- convert(r);
- }
- }return(x);
- }
Thanks Very much!!