.


:




:

































 

 

 

 


. ,




:

, .

a b . , (). 2- .

:

1. r - a b (a>b), a = bq+r, 0 <= r < b.

2. r = 0, b ().

3. r!= 0, (a, b) (b, r), 1.

Microsoft Visual Studio 2013 ( Win32 Console Application) (Empty project). .cpp, .

:

#include <stdio.h>

#include <locale.h>

#include <stdlib.h>

unsigned Evklid(int a, int b)

{

// b

int a1, b1;

if (a>b)

{

a1 = a; b1 = b;

}

else

{

a1 = b; b1 = a;

}

int o;

do

{

o = a1 % b1;

if (o == 0) return b1;

a1 = b1;

b1 = o;

} while (1);

}

 

int main(int argc, char *argv[])

{

int a, b, // -

nod;

setlocale(LC_ALL, "rus"); //

// Windows-1251

if (argc < 3) //

{

printf_s(", . \n");

system("pause");

return 1;

}

//

if (sscanf_s(argv[1], "%d", &a) < 1) // a

{

printf_s(", . \n");

system("pause");

return 1;

}

if (sscanf_s(argv[2], "%d", &b) < 1) // a

{

printf_s(", . \n");

system("pause");

return 1;

}

nod = Evklid(a, b); //

 

printf("a=%d, b=%d, nod=%d. : %d/%d. \n", a, b, nod, a/nod, b/nod);

system("pause"); //

return 0;

}

 

. MyProg.exe, MyProg 66 100

2 , .

6.

6





:


: 2015-10-01; !; : 457 |


:

:

: , .
==> ...

1824 - | 1427 -


© 2015-2024 lektsii.org - -

: 0.008 .