Monday, October 3, 2011

GCD

Program       :  Write a C Program to Compute GCD of Given Two Integers
Created By  :  JABIR PATHAN


#include<stdio.h>
#include<conio.h>
void main()
{
   int i,a,b,gcd,min;
   clrscr();
   printf("enter any two numbers==>\n");
   scanf("%d%d",&a,&b);
  i f(a<b)
   {
     min=a;
    }
   else
   {
    min=b;
   }
   for(i=1;i<=min;i++)
    {
       if(a%i==0&&b%i==0)
       {
         gcd=i;
      }
   }
   printf("gcd of %d and %d is==>%d",a,b,gcd);
   getch();
  }

No comments:

Post a Comment