Solution for Exercise 10-12

ex1012

#include <stdio.h>

void limit(int stop);

int main()
{
    int s;

    printf("Enter a stopping value (0-100): ");
    scanf("%d",&s);
    limit(s);
    return(0);
}

void limit(int stop)
{
    int x;

    for(x=0;x<=100;x=x+1)
    {
        printf("%d ",x);
        if(x==stop)
        {
            puts("You won!");
            return;
        }
    }
    puts("I won!");
}

Notes

* The return at Line 25 serves a siimilar function as a break statement in a loop. The difference is that the break statement continues program execution after the loop; the return sends execution back to the calling statement.