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.
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
This flow chart shows you the logic of the code.
CODE IN C-PROGRAMING
- // finding gcd of any two Number
- #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); // takeing first number from user
- printf("Enter Second Number :");
- scanf("%d",&s_Num); // takeing scond number from user
- if(f_Num < s_Num) // echanging the number if fisrt number is greater than second number
- {
- tempVar = f_Num;
- f_Num = s_Num;
- f_Num = tempVar;
- }
- printf("GCD(%d,%d) :",f_Num,s_Num );
- while(!(s_Num == 0)) // logic of solveing gcd
- {
- gcd = f_Num % s_Num;
- f_Num = s_Num;
- s_Num = gcd;
- }
- printf("%d",f_Num); // printing of gcd
- return 0;
- }
OUTPUT


Saqib FarooqiPosted Oct 26, 2017, 9:54 PM
Good work dear c++ developer