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!"); }
Output
Enter a stopping value (0-100): 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 You won!
Notes
* The return at Line 25 serves a similar 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 out of the function and back to the calling statement.
Copyright © 1997-2024 by QPBC.
All rights reserved