Professional Documents
Culture Documents
GCD of Two Number
GCD of Two Number
You
Not using function
ChatGPT
Here's a simple C program to calculate the Greatest Common Divisor (GCD) of two
numbers without using a function:
c Copy code
#include <stdio.h>
int main() {
int num1, num2, gcd;
// Find GCD
for (int i = 1; i <= num1 && i <= num2; ++i) {
if (num1 % i == 0 && num2 % i == 0) {
gcd = i;
}
}
// Display GCD
printf("GCD of %d and %d is %d\n", num1, num2, gcd);
return 0;
}
This program calculates the GCD of two numbers without using a separate function.
Message ChatGPT…