3. Program to get three numbers from user for integer variables a, b and c. If a is not zero, find out whether it is the common divisor of b and c.

Chapter 5: 

Conditional Structures

Programming Exercise

Problem # 3:

Write a program to get three numbers from user for integer variables a, b and c. If a is not zero, find out whether it is the common divisor of b and c.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
    int a,b,c;
    cout<<"Enter three integer numbers:";
    cin>>a>>b>>c;
    if(a!=0)
    {
        if(b%a==0&&c%a==0)
        cout<<endl<<"a:"<<a<<" is a common divisor of b:"<<b<<"and c:"<<c;
        else
        cout<<endl<<"a:"<<a<<" is not a common divisor of b:"<<b<<"and c:"<<c;
    }
    else
    cout<<"a is zero.";
    return 0;
}


Let me know in the comment section if you have any question.

Previous Post:
2. Program that accepts as input a salesperson's status in the character variable status. If status is 's' or 'S', the senior person's salary should be displayed; if status is 'j' or 'J', the junior person's salary should be displayed, otherwise display error message.

Comments