Subscribe

RSS Feed (xml)

Monday, March 8, 2010

Write a C program to find the greatest common divisor (GCD) of the two given positive integers.

#include< stido.h>
#include< conio.h>
int main( )
{
int a, b, res;
clrscr( );
printf("Enter the two integer values:");
scanf("%d%d", &a, &b);

for( ; ; ) //This is empty for loop.
{
res = a%b;
if( res = = 0) break;
a = b;
b = res;
}
printf("\n The GCF is : %d", res);
getch( );
return 0;
}

5 comments:

  1. printf("\n The GCF is : %d", res)
    in the above statement we hav to make an adjustment else the o/p is always zero.
    the adjustment is:
    printf("\n The GCF is : %d", b)

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I have just started learning computer programming. I found this website very informative. It will help me to get some good programming concepts.

    ReplyDelete
  4. For Best C Programs with Full Explanatons..
    Visit Here ►► Lightning Code

    ReplyDelete
  5. full fledged c language online training we are provieding
    C Online Training

    ReplyDelete