GCD

GCD stands for Greatest Common Divisor. This is a basic operation for students. I am going to show you how it's calculated by using a flow chart. This solution is based on Euclid's GCD.
SYSTEM REQUIRMENT
  1. Windows operating system
  2. GCC compiler
FLOWCHART

This flow chart shows you the logic of the code.



CODE IN C-PROGRAMING
  1. // finding gcd of any two Number
  2. #include <stdio.h> // including INPUT AND OUTPUT HEADER FILE
  3. int main()
  4. {
  5. int f_Num,s_Num,gcd,tempVar;
  6. printf("Enter first Number :");
  7. scanf("%d",&f_Num); // takeing first number from user
  8. printf("Enter Second Number :");
  9. scanf("%d",&s_Num); // takeing scond number from user
  10. if(f_Num < s_Num) // echanging the number if fisrt number is greater than second number
  11. {
  12. tempVar = f_Num;
  13. f_Num = s_Num;
  14. f_Num = tempVar;
  15. }
  16. printf("GCD(%d,%d) :",f_Num,s_Num );
  17. while(!(s_Num == 0)) // logic of solveing gcd
  18. {
  19. gcd = f_Num % s_Num;
  20. f_Num = s_Num;
  21. s_Num = gcd;
  22. }
  23. printf("%d",f_Num); // printing of gcd
  24. return 0;
  25. }
OUTPUT