0% found this document useful (0 votes)
48 views1 page

GCD of Two Number

This C program calculates the greatest common divisor (GCD) of two user-input numbers without using a separate function. It uses a for loop to iterate from 1 to the smaller of the two numbers, finding the largest integer that divides both numbers without a remainder. This common divisor is stored in the gcd variable and printed as the program's output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views1 page

GCD of Two Number

This C program calculates the greatest common divisor (GCD) of two user-input numbers without using a separate function. It uses a for loop to iterate from 1 to the smaller of the two numbers, finding the largest integer that divides both numbers without a remainder. This common divisor is stored in the gcd variable and printed as the program's output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ChatGPT 3.

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;

// Input two numbers from user


printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);

// 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…

ChatGPT can make mistakes. Consider checking important information.

You might also like