Object

Write a program to print the sum of three numbers.

Algorithm

  1. Declare a function int calsum(int x, int y, int z), which accepts three integer arguments and returns an integer value.
    The Function main
  2. Declare integer variables a, b, c and sum.
  3. Read a, b and c.
  4. Call the function calsum(a, b, c) and store the value it returns in sum. (where a, b and c are the actual arguments)
  5. Write sum.
  6. Exit.
    Defining the Function int calsum(int x, int y, int z)
    (where x, y and z are the formal arguments)
  7. Declare integer variable d.
  8. d = x + y + z.
  9. Return (d).
  10. 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

Design a site like this with WordPress.com
Get started