Make a new start with a new Thought!

NOTE :                // indicates comments.This wont get printed in the output.This is used for for documentation purpose. PROGRAM: #incl...

GCD

NOTE :
              
// indicates comments.This wont get printed in the output.This is used for for documentation purpose.

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
   int n1,n2,temp1,temp2,gcd,i;
   clrscr();
   printf("Enter any two numbers to find their G.C.D\n" );
   scanf("%d%d",&n1,&n2);
   temp1=n1;
   temp2=n2;
   for(i=1;(i<=n1) && (i<=n2);)
   {
     if(n1>n2)
     {
        n1=n1-n2;
      }
     else
    {
       n2=n2-n1;
    }
   }
   printf("The G.C.D of %d and %d is %d",temp1,temp2,n1);
   getch();
}

OUTPUT :


0 comments: