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

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

miscelaneous...

File size: 1.3 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 <stdio.h>
11#include <almosmkh.h>
12
13///////////
14void main()
15{
16    int                opx;
17    int                opy;
18    unsigned long long cycle;
19
20    get_cycle( &cycle );
21    printf( "\n\n[PGCD] starts / cycle %d\n", (unsigned int)cycle ); 
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        {
35           printf("operands must be positive and larger than 0 => exit\n");
36           exit( 0 );
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", opx);
46        }
47    }
48} // end pgcd
49
Note: See TracBrowser for help on using the repository browser.