Professional Documents
Culture Documents
A simple calculator program with functions. This program allows the user
to
input two numbers, then passes those two numbers into a sum func
tion, and
finally prints the returned sum.
*/
#include <stdio.h>
/* Define a function that takes two arguments, both of type int, and returns an
int */
int sum (int n1, int n2)
{
int answer;
answer = n1 + n2;
/* Put the sum of the two numbers into a
nswer */
return(answer);
/* Exit
function and return answer */
}
void main (void)
{
int number1, number2, total;
printf ( What is the first number? );
scanf ( %d , &number1);
printf ( What is the second number? );
scanf ( %d , &number2);
total = sum (number1, number2);
umbers from
/*