Hello everybody, pleased to be here. I'm relatively new to programming, just took up learning C a few weeks ago (and not that actively either).

I've run into an assignment that my mentor said "could" be appropriate, but that there's a simpler solution (which she did not say of course -_-), but when I wrote the code in Microsoft Visual Studio C++, the debugger returned no errors, but I can't seem to understand why I get nothing as a result (actually, instead of a number result, I get "-858993460").

The code SHOULD be doing the following: The user types the values of N and M, where N is the number of natural numbers (is it "natural" in English? All whole numbers above 0 that is :P) and M is the paramater. The program is supposed to find the biggest number from 0 to N whose summary of digits is equal to M.

Here's the code I wrote:

Code:

#include <stdio.h>
#include <math.h>
main ()
{
int n,m,i,j,k,p,l,sum,x,max;
printf("Type in the amount of numbers \n");
scanf("%d",&n);
printf("Type in the M paramater \n");
scanf("%d",&m);
for (i=0;i<n;i++);
{
k=1;
for (j=1;j<=k;j++);
{
if (i/pow(10,j)==0)
p=j;
else k++;
}
sum=0;
for (l=p;l>=1;l--)
{
x=(i%(int)pow(10,l))/(pow(10,l-1));
sum=sum+x;
}
if (sum==m)
max=i;
}
printf ("The greatest number whose sumary of digits is equal to M is %d \n",max);
}