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

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

Restructure the mini_libc.

File size: 1.2 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\n");
36        } 
37        else 
38        {
39            while (opx != opy) 
40            {
41                if(opx > opy)   opx = opx - opy;
42                else            opy = opy - opx;
43            }
44            printf("pgcd      = %d", opx);
45        }
46    }
47} // end pgcd
48
Note: See TracBrowser for help on using the repository browser.