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
- Windows operating system
- GCC compiler
FLOWCHART
This flow chart shows you the logic of the code.
CODE IN C-PROGRAMING
-
- #include <stdio.h> // including INPUT AND OUTPUT HEADER FILE
-
- int main()
- {
- int f_Num,s_Num,gcd,tempVar;
-
- printf("Enter first Number :");
- scanf("%d",&f_Num);
-
- printf("Enter Second Number :");
- scanf("%d",&s_Num);
-
- if(f_Num < s_Num)
- {
- tempVar = f_Num;
- f_Num = s_Num;
- f_Num = tempVar;
- }
-
- printf("GCD(%d,%d) :",f_Num,s_Num );
-
- while(!(s_Num == 0))
- {
- gcd = f_Num % s_Num;
- f_Num = s_Num;
- s_Num = gcd;
- }
-
- printf("%d",f_Num);
-
- return 0;
- }
OUTPUT