Write a Program in C That Cube a Variable Using Pass-by-Value

// Cube a variable using pass-by-value.
#include <stdio.h>

int cubeByValue( int n ); // prototype

int main( void )
{
   int number = 5; // initialize number

   printf( "The original value of number is %d", number );
   
   // pass number by value to cubeByValue
   number = cubeByValue( number );

   printf( "\nThe new value of number is %d\n", number );
} // end main

// calculate and return cube of integer argument                 
int cubeByValue( int n )                                            
{                                                                   
   return n * n * n; // cube local variable n and return result
} // end function cubeByValue

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...