whats wrong with my pgcd program ( pgcd meaning written under title

a pgcd ( plus grand commun diviseur ) is the biggest diviseur of 2 numbers
ex: 15 can be divided by 1,3,5,15
30 can be divided by 1,2,3,5,10,15,30
15 is the pgcd



// pgcd revision.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
using namespace std;
int main ()
{
int x;
int y;
int i;
int max=0;
int min=0;


cout << " enter the first number" ;
cin >> x ;
cout <<" enter second number " ;
cin >> y ;

if ( x>=y )
{
x=max;
y=min;
}
if (x<=y)
{
x=min;
y=max;
}

for ( i=max ; i>= min ; i--)

while ( max%i != 0 || min%i !=0 )

cout << " " <<i << endl;

system ("pause");
return 0;
}
A number between the max and the min will never be a divisor of the min. You probably want your for loop to be for (i = min; i > 0; i--)

When you post code, you should wrap you code in code tags. Click the Format button labeled "<>" and post your code between the tags. Or, highlight the code and then click the button.

Edit: Also, you don't need a while statement--you should change that to an if statement with the opposite logic. To better understand how loops work, read the following tutorial page from this site.

http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Topic archived. No new replies allowed.