Last change
on this file since 441 was
436,
checked in by alain, 7 years ago
|
1) improve the threads and process destruction mechanism.
2) introduce FIFOs in the soclib_tty driver.
|
File size:
1.2 KB
|
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 | |
---|
| 10 | #include <stdlib.h> |
---|
[436] | 11 | #include <stdio.h> |
---|
[417] | 12 | |
---|
| 13 | |
---|
| 14 | /////////// |
---|
| 15 | void main() |
---|
| 16 | { |
---|
[436] | 17 | int opx; |
---|
| 18 | int opy; |
---|
| 19 | unsigned long long cycle; |
---|
[417] | 20 | |
---|
[436] | 21 | get_cycle( &cycle ); |
---|
| 22 | printf( "\n[PGCD] starts / cycle %d\n", (unsigned int)cycle ); |
---|
[417] | 23 | |
---|
| 24 | while (1) |
---|
| 25 | { |
---|
| 26 | printf("\n*******************\n"); |
---|
| 27 | printf("operand X = "); |
---|
| 28 | opx = getint(); |
---|
| 29 | printf("\n"); |
---|
| 30 | printf("operand Y = "); |
---|
| 31 | opy = getint(); |
---|
| 32 | printf("\n"); |
---|
| 33 | |
---|
| 34 | if( (opx == 0) || (opy == 0) ) |
---|
| 35 | { |
---|
| 36 | printf("operands must be positive and larger than 0\n"); |
---|
| 37 | } |
---|
| 38 | else |
---|
| 39 | { |
---|
| 40 | while (opx != opy) |
---|
| 41 | { |
---|
| 42 | if(opx > opy) opx = opx - opy; |
---|
| 43 | else opy = opy - opx; |
---|
| 44 | } |
---|
| 45 | printf("pgcd = %d\n", opx); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | } // end pgcd |
---|
| 49 | |
---|
Note: See
TracBrowser
for help on using the repository browser.