I am new to C Programming, and doing a pratice exerises on GCD. The 
program works with no problems, but I would like to use two seperate 
entries to input the first and second numbers,


[code] 
#include <stdio.h>

int gcd(int a,int b)
{
        int r;

   if((r = a%b)==0)
        return b;
   else
        return gcd(b,r);
}

int main()
{
  int n1,n2;
  printf("Enter two numbers to find its GCD: /n");
  scanf_s("%d %d",&n1, &n2);
  printf("The GCD of %d and %d \n is %d\n",n1,n2,gcd(n1,n2));
  return 0;
}
[code]

I think this is how my new main function should look, but when i run 
the program it gives me a debug error, and the program stops. 

int main()
{
  int n1,n2;
  printf("Enter the first number to find its GCD: ", n1);
  scanf_s("%d %d",&n1);
  printf("Enter the second number to find its GCD: ", n2);
  scanf_s("%d %d",&n2);
  printf("The GCD of %d and %d \n is %d\n",n1,n2,gcd(n1,n2));
  return 0;
}

Any help is greatly appreciated.

Reply via email to