This program reads an integer n of M digits (defined at the beginning) and a one-digit integer d; if d is in n it has to print n and and the sum (+) symbol below every occurance of d.

It compiles, and works fine in the case M=1,2 and 3, but it starts doing funny things when M=4 and up...

Any advice is appreciated.

Thanks!

Code:#include <stdio.h> #include <stdlib.h> #include <math.h> #define M 4 int procesar(int n, int d); int procesar(int n, int d) { int esta=0; int i,aux; for(i=0;i<M;i++) { aux=n/pow(10,M-(i+1)); if(aux==d) { esta=1; printf("+"); } else printf(" "); n=n-(aux*pow(10,M-(i+1))); } return esta; } int main() { int n,d; scanf("%d %d",&n,&d); printf("%d\n",procesar(n,d)); system("PAUSE"); return 0; }