update README.md for tasks 1 & 2
This commit is contained in:
63
2. problem_cf/README.md
Normal file
63
2. problem_cf/README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Problem CF - непрерывные дроби
|
||||
|
||||
Вам на вход приходят числитель и знаменатель дроби.
|
||||
|
||||
**Ваша задача**: написать программу выдающую на стандартный вывод представление цепной дробью.
|
||||
|
||||
## Пример 1
|
||||
|
||||
| Ввод | Вывод |
|
||||
| ------------- | -------------- |
|
||||
| `1 3` | `0 3` |
|
||||
|
||||
## Пример 2
|
||||
|
||||
| Ввод | Вывод |
|
||||
| ------------- | -------------- |
|
||||
| `43 19` | `2 3 1 4` |
|
||||
|
||||
## Пример 3
|
||||
|
||||
| Ввод | Вывод |
|
||||
| ------------- | -------------- |
|
||||
| `345 678` | `0 1 1 27 1 3` |
|
||||
|
||||
# Решение
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define ull unsigned long long
|
||||
|
||||
void cf(ull x, ull y);
|
||||
|
||||
int main() {
|
||||
ull x = 0, y = 0;
|
||||
int res;
|
||||
|
||||
res = scanf("%llu %llu", &x, &y);
|
||||
assert(res == 2);
|
||||
|
||||
cf(x, y);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cf(ull x, ull y) {
|
||||
ull a = x;
|
||||
ull b = y;
|
||||
|
||||
ull q = a / b;
|
||||
ull r = a % b;
|
||||
printf("%llu ", q);
|
||||
|
||||
while (r > 0) {
|
||||
a = b;
|
||||
b = r;
|
||||
q = a / b;
|
||||
r = a % b;
|
||||
printf("%llu ", q);
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user