• Source
    1. #include<stdio.h>
    2. int main()
    3. {
    4. int copy_num_1,copy_num_2,num_1,num_2,gcd,i ;
    5. printf("Please, Enter two numbers : ");
    6. scanf("%d%d",&num_1,&num_2);
    7. copy_num_1=num_1;
    8. copy_num_2=num_2;
    9. //copying numbers , (entered by user) for future use.
    10. if(num_1<0)
    11. num_1=(num_1)*(-1);
    12. if(num_2<0)
    13. num_2=(num_2)*(-1);
    14. //here, we are converting negative numbers(if any, entered by user), so that, we can calculate the gcd for both positive and negative numbers.
    15. for(i=1;i<=num_1 && i<=num_2;i++)
    16. {
    17. if(num_1%i==0 && num_2%i==0)
    18. gcd=i;
    19. }
    20. printf("\nThe GCD of %d and %d is : %d",copy_num_1,copy_num_2,gcd);
    21. return 0;
    22. }