C Program- To generate GCD

Posted: January 19, 2012 in Lab 2
#include<stdio.h>
#include<string.h>
int gcd2(int, int);
int gcd2(int a, int b)
{
	if(b==0)
		return a;
	else
	{
		a=a%b;
		return gcd2(b,a);
	}
}
int main()
{
	int a,b=0,ans;
		scanf("%d%d",&a,&b);
		if(a==0)
		{
			printf("%d\n",b);
		}
		ans=gcd2(a,b);
		printf("%d\n",ans);
	return 0;
}
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