#include<stdio.h>
int main()
 {
     int a,b,c;
     (printf("\nEnter 2 no.s"))?(scanf("%d%d",&a,&b))?(c=(a>b)?a:b):0:0;
      while(c>=1)
       {if(a%c==0 && b%c==0)
         {printf("\nGCD:%d",c);return 0;}
        c--;
       }

 }

this code works fine in gcc compiler (for windows u need codeblocks compiler)

to download compiler visit <link removed>

And is this abominable code useful in some way? Other than to show how not to code?

How about this?:

int gcd(int x, int y)
{
   if ((x % y) == 0)
      return y;

   return gcd(y, x % y);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.