Solution for Exercise 10-6
ex1006
#include <stdio.h> void graph(int count); int main() { int value; value = 2; while(value<=64) { graph(value); printf("Value is %d\n",value); value = value * 2; } return(0); } void graph(int count) { int x; for(x=0;x<count;x=x+1) putchar('*'); putchar('\n'); }
Notes
* The equation at Line 15 doubles the value of variable value
each time the loop is run. Because value
starts out equal to 2, you see a graph representing powers of 2.
* It's possible to prototype a function without listing the argument with a variable name, officially known as the parameter name. So you could replace Line 3 with this:
However, when you write the function in the code (at Line 20), you must specify the parameter name, which then becomes the local variable referencing the passed argument.
Copyright © 1997-2024 by QPBC.
All rights reserved