Program to find the Greatest Common Division (GCD) using while loop

/* Program: The while loop */
    #include <iostream.h>
    void main()
    {
        int num_1 , num_2 ;
        cout<<"Enter any two integer values :\n";
        cin>>num_1>>num_2 ;

        while ((num_1!=0) && (num_2!=0))
        {
            if (num_1 > num_2)
                num_1 = num_1 - num_2 ;
            else
                num_2 = num_2 - num_1 ;
        }

        cout<<"The GCD is "<<num_1;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|