WAP in C to Find GCD of two Numbers?

#include<stdio.h>
#include<conio.h>
int main()
{
int n1, n2, i, g;
clrscr();
printf(“Enter two numbers: “);
scanf(“%d %d”, &n1, &n2);
for(i=1; i <= n1 && i <= n2; ++i)
{
if(n1%i==0 && n2%i==0)
g = i;
}
printf(“G.C.D of %d and %d is %d”, n1, n2, g);
getch();
return(0);
}

Output :-

gcd

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s