Write two versions of a program that displays the follwing table:
X X cubed
------------- -----------
Have the table continue until X is 20.
a. For the first version, write a function to do the cube calculation that takes
a single parameter. If the parameter is 2 on entry to the function, the parameter
should have the value 8 on exit from the function. That is, implement a
"pass by reference" on the function's parameter and have the cubed value
passed back in the parameter.
b. For the second version, write a function that does the cubing, but, have
the cubed value passed back to the main program as the return balue of the function.
C program.....?
Well your table looks a little messed up, but I can help you with the functions.
a would look like this...
void cubebyref(int %26amp;x)
{
x=x*x*x;
}
b would look like
int cubebyreturn(int x)
{
return x*x*x;
}
Hope that helps.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment