fork download
  1. #include <stdio.h>
  2.  
  3. int add_values (int number1, int number2) /* two parameters, number1 and number 2 */
  4.  
  5. { /* start of function body */
  6.  
  7. int result; /* local variable to hold add result */
  8.  
  9. result = number1 + number2;
  10.  
  11. return (result); /* the value contained in result is returned to the calling function, in this case, main */
  12.  
  13. } /* end of function body */
  14.  
  15. int main ( )
  16. {
  17.  
  18. int value1; /* local variable */
  19. int value2; /* another local variable */
  20. int answer; /* and yet another local variable */
  21.  
  22. printf ("\n Enter an integer value: ");
  23. scanf ("%i", &value1);
  24.  
  25. printf ("\n Enter another integer value: ");
  26. scanf ("%i", &value2);
  27.  
  28. answer = add_values (value1, value2); /* pass two arguments, value1 and value2, to add_values */
  29.  
  30. printf ("\n Adding %i to %i equals %i", value1, value2, answer);
  31.  
  32. return (0);
  33.  
  34. }
Success #stdin #stdout 0s 5292KB
stdin
6
15
stdout
 Enter an integer value: 
 Enter another integer value: 
 Adding 6 to 15 equals 21