Functions
- Example 1
- #include <stdio.h>
- int cube (int x);         /* function prototype */
- int main(){
- int input_num, func_result;
- printf("please, enter the integer: ");
- scanf("%d", &input_num);
- func_result = cube (input_num);      /* function call (invokation) */
- printf("The cube of %d is %d\n ", input_num, func_result);
- return 0;
- } /* end main function */
- /* definition of the function cube */
- /* function cube has one integer parameter and returns the cube of parameter */
- int cube (int x){
- int res;
- res = x*x*x:
- return res;
- }/* end function cube */
- Example 2
- #include <stdio.h>
- int cube (int x);         /* function prototype */
- int main(){
- int x;
- printf("please, enter the integer: ");
- scanf("%d", &x);
- printf("The cube of %d is %d\n ",x, cube (x) ); /* function call inside printf */
- return 0;
- } /* end main function */
- /* definition of the function cube */
- /* function cube has one integer parameter and returns the cube of parameter */
- int cube (int x){
- }/* end function cube */
- Example 3
- #include <stdio.h>
- int cube (int x);         /* function prototype */
- int main(){
- int x, i;
- printf("please, enter the integer: ");
- scanf("%d", &x);
- printf("the cubes of all numbers between 0 and %d are\n: " , x);
- for (i = 0; i<= x; i++){
- }
- return 0;
- } /* end main function */
- /* definition of the function cube */
- /* function cube has one integer parameter and returns the cube of parameter */
- int cube (int x){
- }/* end function cube */