Rev | Line | |
---|
[417] | 1 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : pgcd.c |
---|
| 3 | // Date : November 2017 |
---|
| 4 | // Author : Alain Greiner <alain.greiner@lip6.fr> |
---|
| 5 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 6 | // This single thread interactive application computes the PGCD. |
---|
| 7 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 8 | |
---|
| 9 | |
---|
[436] | 10 | #include <stdio.h> |
---|
[445] | 11 | #include <almosmkh.h> |
---|
[417] | 12 | |
---|
| 13 | /////////// |
---|
| 14 | void main() |
---|
| 15 | { |
---|
[436] | 16 | int opx; |
---|
| 17 | int opy; |
---|
| 18 | unsigned long long cycle; |
---|
[417] | 19 | |
---|
[436] | 20 | get_cycle( &cycle ); |
---|
[445] | 21 | printf( "\n\n[PGCD] starts / cycle %d\n", (unsigned int)cycle ); |
---|
[417] | 22 | |
---|
| 23 | while (1) |
---|
| 24 | { |
---|
| 25 | printf("\n*******************\n"); |
---|
| 26 | printf("operand X = "); |
---|
| 27 | opx = getint(); |
---|
| 28 | printf("\n"); |
---|
| 29 | printf("operand Y = "); |
---|
| 30 | opy = getint(); |
---|
| 31 | printf("\n"); |
---|
| 32 | |
---|
| 33 | if( (opx == 0) || (opy == 0) ) |
---|
| 34 | { |
---|
[446] | 35 | printf("operands must be positive and larger than 0 => exit\n"); |
---|
| 36 | exit( 0 ); |
---|
[417] | 37 | } |
---|
| 38 | else |
---|
| 39 | { |
---|
| 40 | while (opx != opy) |
---|
| 41 | { |
---|
| 42 | if(opx > opy) opx = opx - opy; |
---|
| 43 | else opy = opy - opx; |
---|
| 44 | } |
---|
[442] | 45 | printf("pgcd = %d", opx); |
---|
[417] | 46 | } |
---|
| 47 | } |
---|
| 48 | } // end pgcd |
---|
| 49 | |
---|
Note: See
TracBrowser
for help on using the repository browser.