| Rev | Line | |
|---|
| [25] | 1 | #include "stdio.h" |
|---|
| 2 | |
|---|
| 3 | /////////// |
|---|
| 4 | int main2() |
|---|
| 5 | { |
|---|
| 6 | int opx; |
|---|
| 7 | int opy; |
|---|
| 8 | int x; |
|---|
| 9 | int y; |
|---|
| 10 | |
|---|
| 11 | tty_puts(" TASK 2 : PGCD \n"); |
|---|
| 12 | |
|---|
| 13 | while (1) |
|---|
| 14 | { |
|---|
| 15 | tty_puts("\n*******************\n"); |
|---|
| 16 | tty_puts("operand X = "); |
|---|
| 17 | tty_getw_irq(&opx); |
|---|
| 18 | tty_puts("\n"); |
|---|
| 19 | tty_printf("operand Y = "); |
|---|
| 20 | tty_getw_irq(&opy); |
|---|
| 21 | tty_puts("\n"); |
|---|
| 22 | |
|---|
| 23 | if( (opx < 1) || (opy < 1) ) |
|---|
| 24 | { |
|---|
| 25 | tty_puts("operands must be larger than 0\n"); |
|---|
| 26 | } |
|---|
| 27 | else |
|---|
| 28 | { |
|---|
| 29 | x = opx; |
|---|
| 30 | y = opy; |
|---|
| 31 | while (x != y) |
|---|
| 32 | { |
|---|
| 33 | if(x > y) x = x - y; |
|---|
| 34 | else y = y - x; |
|---|
| 35 | } |
|---|
| 36 | tty_printf("pgcd(%d,%d) = %d\n", opx, opy, x); |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | return 0; |
|---|
| 40 | } // end main |
|---|
Note: See
TracBrowser
for help on using the repository browser.