What is the fastest way to find the GCD of two numbers?

后端 未结 4 894
鱼传尺愫
鱼传尺愫 2020-12-22 12:48

I have an array of size n. I need to find the GCD of each element with a given number and if it\'s greater than 1, add it to another array. What\'s the fastest way to do thi

4条回答
  •  没有蜡笔的小新
    2020-12-22 13:24

    #include
    int main()
    {
       int a,b,a1,b1;
       printf("Enter two numbers:");
       scanf("%d%d",&a,&b);
       a1=a;b1=b;
       while(a!=b)
       {
          if(a>b)
            a=a-b;
          else
            b=b-a;
       }
       printf("GCD of %d and %d is %d\n",a1,b1,a);
       printf("LCM of %d and %d is %d",a1,b1,(a1*b1/a));
    }
    

提交回复
热议问题