Object

Write a program that reads two integers, divides one integer by another and returns the quotient and the remainder in function main.

Algorithm

  1. Declare a function void divide(int *quo, int *rem, int x, int y) that accepts two integer pointers and two integers as arguments and returns no value.
    The Function main
  2. Declare integer variables a, b, quo and rem.
  3. Read a and b.
  4. Call the function divide(&quo, &rem, a, b) considering a and b and addresses of quo and rem as actual arguments.
  5. Write quo and rem.
  6. Exit.
    Defining the Function void divide(int *quo, int *rem, int x, int y)
    where *quo, *rem and x and y are the formal arguments
  7. *quo = x/y.
  8. *rem = x%y.
  9. Exit.

Flowchart

C++ Source Code

// program 105
#include<iostream>
using namespace std;

void divide(int *quo, int *rem, int x, int y);

int main()
{
  int a, b, quo, rem;
  cout << "Enter any two numbers = ";
  cin >> a >> b;
  divide(&quo, &rem, a, b);
  
  cout << "\nThe Quotient of " << a << "/" << b << " is: " << quo << endl;
  cout << "The Remainder of " << a << "/" << b << " is: " << rem << endl;

  return 0;
}

void divide(int *quo, int *rem, int x, int y)
{
  *quo = x / y;
  *rem = x % y;
}

C Source Code

/*program 105*/
#include<stdio.h>

void divide(int *, int *, int, int);

int main()
{
  int a, b, quo, rem;
  printf("\nEnter any two numbers = ");
  scanf("%d%d", &a, &b);
  divide(&quo, &rem, a, b);
  printf("\nThe Quotient of %d/%d is: %d", a, b, quo);
  printf("\nThe Remainder of %d/%d is: %d", a, b, rem);
  
  return 0;
}

void divide(int *quo, int *rem, int x, int y)
{
  *quo = x / y;
  *rem = x % y;
}

Output

Enter any two numbers = 34 6

The Quotient of 34/6 is: 5
The Remainder of 34/6 is: 4

Design a site like this with WordPress.com
Get started