Skip to content

Commit 98db624

Browse files
committed
return values gcd
1 parent 9588803 commit 98db624

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

prog.8.6.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Function to find the greatest common divisor of two
2+
nonnegative integer values and to return the result */
3+
4+
#include <stdio.h>
5+
6+
int gcd (int u, int v)
7+
{
8+
int temp;
9+
10+
while ( v != 0 ) {
11+
temp = u % v;
12+
u = v;
13+
v = temp;
14+
}
15+
16+
return u;
17+
}
18+
19+
int main (void)
20+
{
21+
int result;
22+
23+
result = gcd (150, 35);
24+
printf ("The gcd of 150 and 35 is %i\n", result);
25+
26+
result = gcd (1026, 405);
27+
printf ("The gcd of 1026 and 405 is %i\n", result);
28+
29+
printf ("The gcd of 83 and 240 is %i\n", gcd (83, 240));
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)