‘C’ program to calculate the GCD of two numbers.

C File =>


/* Write a ‘C’ program to calculate the GCD of two numbers. */

#include<stdio.h>
int main() 
{
      int m, n;
 
      printf("Enter two positive integers: ");
      scanf("%d %d",&m,&n);
 
      while(m!=n)
      {
           if(m > n)
                m = m - n;
          else
                n = n - m;
       }
 
      printf("GCD = %d",m);
 
      return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.