C & C++: This program will figure out the greatest common divisor in two numbers you give

  • faust / 200 / Tues, 05 May 2009 18:10:00 GMT / Comments (0)
  • #include
    #define d b%a
    #define e a%b

    void main()
    {
    int a,b,c,y,z,m,n;
    printf("This program will figure out the greatest common divisor in two numbers you give.\n");
    printf("Please enter the first number.\n");
    scanf("%d",&a);
    printf("Please enter the second number.\n");
    scanf("%d",&b);
    if(b>a)
    {
    if(d==0)
    c=a;

    if(d==1)
    c=1;

    if(d>1)
    {
    while(d!=0 && d!=1)
    {
    y=a%(d);
    a=b;
    d=a;
    }
    if((d)==0)
    a=c;
    if((d)==1)
    c=1;
    }
    }

    if(a>b)
    {
    if((e)==0)
    b=c;

    if((e)==1)
    c=1;

    if((e)>1)
    {
    while(a%b!=0 && a%b!=1)
    {
    z=b%(e);
    b=a;
    e=b;
    }
    if((e)==0)
    b=c;
    if((e)==1)
    c=1;
    }
    }

    if(a==b)
    c=a;

    printf("The GCD is %d",c);
    }
  • Keywords:

    program, figure, out, greatest, common, divisor, two, numbers, give, c++

  • http://programming.itags.org/c-c++/199414/«« Last Thread - Next Thread »»
  • C & C++ Questions

    • This line has many unspeakable style sins.

      "Martin Ambuhl" wrote in message> if (2 != (nread = sscanf(input, "%d%d", &first, &second))) {>This...

      By malcolm

    • Sybase OC Library

      I wasn't able to get a response from sybase usergroup forum. Hopefully,I'll get some help ...

      By ollie

    • select() for iostreams

      Is there anything in the STL (or boost) which would work like select()does for file descriptors? I h...

      By brian_cain

    • Sybase OC Library

      I wasn't able to get a response from sybase usergroup forum. Hopefully,I'll get some help here.I am ...

      By ollie