On Mon, Nov 10, 2008 at 9:25 PM, pm rao <[EMAIL PROTECTED]> wrote:

> Could you please help me out in analysing this issue:
>
> I really find strange behavior with the following code. If the
> statement b is present as below, the for loop is executing infinitely.
> But when statement b is replaced with statement a as
> int c[31], s[31];. Then the for loop is exited after n iterations.
> Below is my gcc version where i executed the code. Please help me out
> in this regard.

Your code executes as expected for me (using gcc under CygWin).
However, a couple of things to note:

> int c [30], s[30]; // statement b
>
> #include <stdio.h>
> void change (int a[], int, int);
> int main ()
> {
> int d[3];
> d[0] = 1, d[1] = 10, d[2] = 25;
> int n = 30, k = 3;
> change (d, k, n);
> return 1;
> }

main() should return 0 on successful completion

> void change (int d[], int k, int n)
> {
> int c [30], s[30]; // statement b
> c[0] = 0;
> int p;
> int min, i, coin = 0;
>
> for (p=1; p<=n; p++)

Tradtionally, you start a loop on 0 and go to n - 1.

for(p = 0; p < n; p++)

> {
> c[p] = 0;
> s[p] = 0;
> printf ("\n test : %d \n", p);
> }
> }

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to