Object
Write a program to print the sum of three numbers.
Algorithm
- Declare a function int calsum(int x, int y, int z), which accepts three integer arguments and returns an integer value.
The Function main - Declare integer variables a, b, c and sum.
- Read a, b and c.
- Call the function calsum(a, b, c) and store the value it returns in sum. (where a, b and c are the actual arguments)
- Write sum.
- Exit.
Defining the Function int calsum(int x, int y, int z)
(where x, y and z are the formal arguments) - Declare integer variable d.
- d = x + y + z.
- Return (d).
- Exit.
Flowchart

C++ Source Code
// program 76
#include<iostream>
using namespace std;
int calsum(int x, int y, int z);
int main()
{
int a, b, c, sum;
cout << "Enter three numbers: ";
cin >> a >> b >> c;
sum = calsum(a, b, c);
cout << "The sum of three numbers = " << sum;
return 0;
}
int calsum(int x, int y, int z)
{
int d;
d = x + y + z;
return d;
}
C Source Code
/*program 76*/
#include<stdio.h>
int calsum(int x, int y, int z);
int main()
{
int a, b, c, sum;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
sum = calsum(a, b, c);
printf("The sum of three numbers = %d", sum);
return 0;
}
int calsum(int x, int y, int z)
{
int d;
d = x + y + z;
return(d);
}
Output
Enter three numbers: 5 12 77
The sum of three numbers = 94
