Wednesday, August 17, 2011

QUES6 GCD OF TWO NO


C LANGUAGE BOOK





/*
WAP TO FIND THE GCD OF TWO NUMBERS.
*/
#include<stdio.h>

int main(void)
{
int a;

int i,j;

printf("\nENTER TWO NUMBERS TO FIND \nTHE GCD OF THESE NUMBER");
printf("\n\nENTER THE FIRST NUMBER : \n");
scanf("%d", &i);
printf("\nENTER THE SECOND NUMBER : \n");
scanf("%d", &j);
printf("\nTHE TWO NUMBERS ARE : \n%d%s%d", i, " ", j);

if(i > j)
  GCD(i, j);
else
if(j > i)
  GCD(j, i);
}

GCD(int i, int j)
{
int a;
a = i % j;
if(a == 0)
  printf("\n\nTHE GCD OF TWO NUMBER IS\n%s%d%s", " ", j, " ");
else
  GCD(j, a);
}













C LANGUAGE BOOK

No comments:

Post a Comment