Pages

Monday, 22 June 2015

GCD using loop

GCD of two numbers using loop

Coding:

#include<stdio.h>
int main()
{
int no1,no2,temp,n1,n2;
printf("\n Please entet the first number:");
scanf("%d",&no2);
printf("\n Please enter the second number:");
scanf("%d",&no1);
n1=no1;
n2=no2;
while(no2%no1!=0)
{
temp=no1;
no1=no2%no1;
no2=temp;
}
printf("\n The GCD is=%d",no1);
return 0;
}

Output:
Please entet the first number:8
Please enter the second number:4
The GCD is=4