Calculating Sum in a Function For this part you will implement a simple function, called addTwoNumbers(), that computes the sum of two given numbers. Example of Compilation and Execution: This program will compute the sum of two numbers. Enter the first number: 3 Enter the second number: 2 3 + 2 = 5 Notes: Use this as main: #include int addTwoNumbers(int, int) ; int main () { int num1, num2, sum; printf("This program will compute the sum of two numbers.\n\n") ; printf("Enter the first number: ") ; scanf("%d", &num1) ; printf("Enter the second number: ") ; scanf("%d", &num2) ; sum = addTwoNumbers(num1, num2) ; printf("%d + %d = %d\n", num1, num2, sum); return 0 ; } /* end of main() function */ Below the main program, write the C code to implement the addTwoNumbers() function, giving meaningful names to your parameters. To compute the sum, use and return a local variable called sum. Be sure to use the “+=” operator in your function.
Calculating Sum in a Function
For this part you will implement a simple function, called addTwoNumbers(), that computes the sum of two given numbers.
Example of Compilation and Execution:
This
Enter the first number: 3
Enter the second number: 2
3 + 2 = 5
Notes:
Use this as main:
#include <stdio.h>
int addTwoNumbers(int, int) ;
int main () {
int num1, num2, sum;
printf("This program will compute the sum of two numbers.\n\n") ;
printf("Enter the first number: ") ;
scanf("%d", &num1) ;
printf("Enter the second number: ") ;
scanf("%d", &num2) ;
sum = addTwoNumbers(num1, num2) ;
printf("%d + %d = %d\n", num1, num2, sum);
return 0 ;
}
/* end of main() function */
Below the main program, write the C code to implement the addTwoNumbers() function, giving meaningful names to your parameters.
To compute the sum, use and return a local variable called sum.
Be sure to use the “+=” operator in your function.
Step by step
Solved in 2 steps