source: trunk/user/pgcd/pgcd.c @ 417

Last change on this file since 417 was 417, checked in by alain, 6 years ago

Introduce sort and pgcd applications.

File size: 1.1 KB
Line 
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>
11
12
13///////////
14void main()
15{
16    int opx;
17    int opy;
18
19    printf( "*** Starting interactive pgcd ***\n\n" ); 
20
21    while (1) 
22    {
23        printf("\n*******************\n");
24        printf("operand X = ");
25        opx = getint();
26        printf("\n");
27        printf("operand Y = ");
28        opy = getint();
29        printf("\n");
30
31        if( (opx == 0) || (opy == 0) ) 
32        {
33           printf("operands must be positive and larger than 0\n");
34        } 
35        else 
36        {
37            while (opx != opy) 
38            {
39                if(opx > opy)   opx = opx - opy;
40                else            opy = opy - opx;
41            }
42            printf("pgcd      = %d\n", opx);
43        }
44    }
45} // end pgcd
46
Note: See TracBrowser for help on using the repository browser.