C Programming

Answer: EXERCISE C15

Write a program in C which incorporates a function using parameter passing and performs the addition of three numbers. The main section of the program is to print the result.


	#include <stdio.h>
	int calc_result( int, int, int );

	int calc_result( int var1, int var2, int var3 )
	{
	  int sum;

	  sum = var1 + var2 + var3;
	  return( sum );           /* return( var1 + var2 + var3 ); */
	}

	main()
	{
	  int numb1 = 2, numb2 = 3, numb3=4, answer=0;

	  answer = calc_result( numb1, numb2, numb3 );
	  printf("%d + %d + %d = %d\n", numb1, numb2, numb3, answer);
	}

©Copyright B Brown. 1984-1999. All rights reserved.