Saturday, 25 February 2012

GCD using While loop

#include<iostream>
using namespace std;

int main()
{
int num1; 
int num2; 
int remainder = 0;

cout << "***** Program for finding GCD using While loop*****: "<<endl;
cout << "NOTE: First Number shoulb be greater and both number shoulb be greater than 0."<<endl;
cout << "Enter First Number: ";
cin >> num1;
cout << "Enter Second Number: ";
cin >> num2;
cout << "Answer is = " ;
if(num1<num2)
{
cout << "Sorry You Have Entered Second Number Greater Than Fisrt Number...." <<endl;
}
else
{
while( num2 != 0 )
{
remainder = num1 % num2;
num1 = num2;
num2 = remainder;


cout << num1 <<endl;
}
return 0;
}

No comments:

Post a Comment