School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

C Source Code


Welcome to Dream.In.Code
Become an Expert!

Join 340,149 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,871 people online right now. Registration is fast and FREE... Join Now!




Finding GCD of two numbers using Euclid's Algorithm

Finds the GCD/HCF of a number using Euclid's Recursive Algorithm.

Submitted By: born2c0de
Actions:
Rating:
Views: 22,901

Language: C

Last Modified: October 30, 2005

Snippet


  1. /*
  2.       Written by Sanchit Karve A.K.A born2c0de
  3.            born2c0de AT hotmail DOT com
  4. */
  5. #include <stdio>
  6.  
  7. int euclid(int a,int b)
  8. {
  9.    if(b==0)
  10.         return a;
  11.    else
  12.         return euclid(b,a%b);
  13. }
  14.  
  15. int main()
  16. {
  17.   int n1,n2;
  18.   printf("Enter two numbers to find its GCD:");
  19.   scanf("%d %d",&n1,&n2);
  20.   printf("The GCD of %d and %d is %d",n1,n2,euclid(n1,n2));
  21.   return 0;
  22. }
  23.  
  24.  

Copy & Paste


Comments

ISAI 2008-01-16 14:21:49

Good job. very helpful, thanks a lot =]

Dike 2009-04-29 00:47:48

I was looking for this. Thank you so much


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month