GCD with 3 integers

Hello! im trying to make programm with while loop.
I need to enter three integers and i cant get it to output me greatest common divisor.
maybe someone can help finding my mistake ?

first code with while loop:

#include <conio.h>
#include <iostream.h>

void main()
{
int x,y,z;
int d;
cout<<"input 1 integer - ";
cin>>x;
cout<<"input 2 integer - ";
cin>>y;
cout<<"input 3 integer - ";
cin>>z;
d=1;
while(d>0)
{
x%d==0;
y%d==0;
z%d==0;
d++;


cout<<"Greatest common divisor -"<<d<<" ";

getch();
}}


and this code with do while loop:


#include <conio.h>
#include <iostream.h>

void main()
{
int x,y,z;
int d;
cout<<"input first - ";
cin>>x;
cout<<"input second - ";
cin>>y;
cout<<"input third number - ";
cin>>z;
d=0;
do{
d=d+1;


}while((x/d)||(y/d)||(z/d));
cout<<"GCD is "<<d<<" ";

getch();
}


please help me finding mistake
sry for troubling.. i found the solution ;)

here is code if some one need it:
#include <conio.h>
#include <iostream.h>

void main()
{
int x,y,z;
int d,i;
cout<<"first number - ";
cin>>x;
cout<<"second number - ";
cin>>y;
cout<<"third number - ";
cin>>z;
d=1;
i=1;
while(i<=x&&i<=y&&i<=z){
if(x%i==0&&y%i==0&&x%i==0)
d=i;
i++;
}
cout<<"GCD to -"<<x<<" "<<y<<" "<<z<<" is "<<d<<" ";

getch();
}
Topic archived. No new replies allowed.