Tcs question find out gcd of two number in c using command line

#include <stdio.h>


 int main(int argc, char *argv[])
 {

 int gcd,i,num1,num2=0;
  num1=atoi(argv[1]);
  num2=atoi(argv[2]);
   
  
  for(i=1;i<=num1 && i<=num2;i++){
      
      if(num1%i==0 && num2%i==0){
      gcd=i;
          
      }
  }
  printf("GCD is :%d",gcd);

return 0;
}


No comments:

Post a Comment