C Online Compiler
Example: C Program to Find GCD of Two Numbers using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find GCD of Two Numbers using For loop #include <stdio.h> int main() { int p, q, i, g; // p & q - To store the two positive numbers // g - To store the GCD number printf("----Enter the two positive integer numbers-----\n"); scanf("%d %d", &p, &q); for (i = 1; i <= p && i <= q; ++i) { if (p % i == 0 && q % i == 0) { g = i; } } printf("\nThe GCD number of %d & %d is: %d\n", p, q, g); return 0; }
172 90
Output
Clear
ADVERTISEMENTS