Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 2 KB
#include <stdio.h>
#include <stdlib.h>
void tort_kivon(long int, long int, long int, long int, long int*, long int*);
long int lnko(long int, long int);
void swapxy(long int* , long int*);
long int main() {
long int is, in, an, db = 0, max = 0;
scanf("%u %u", &is, &in);
printf("Tortek: \n");
an = 2;
while(is != 0) {
if(is == 1) {
printf(" %u / %u\n\n", 1, in);
is = 0;
max = in;
db++;
} else if(is * an >= in) {
printf(" %u / %u\n", 1, an);
tort_kivon(is, in, 1, an, &is, &in);
db++;
}
an++;
}
printf("Statisztika: \n");
printf( " db = %u\n"
" max = %u\n\n", db, max);
getch();
}
void tort_kivon(long int as, long int an, long int bs, long int bn, long int *cs, long int *cn) {
long int l;
as *= bn;
bs *= an;
*cs = as - bs;
*cn = an * bn;
l = lnko(*cs, *cn);
*cs /= l;
*cn /= l;
return;
}
long int lnko(long int x, long int y) {
long int m;
if(x > y) swapxy(&x, &y);
m = y % x;
while(m != 0) {
y = x;
x = m;
m = y % x;
}
return x;
}
void swapxy(long int *x, long int *y) {
long int i;
i = *x;
*x = *y;
*y = i;
}
#include <stdio.h>
#include <stdlib.h>
#define ELEMEK 32767
int main() {
long int is, in, i, j, c;
long int tomb[ELEMEK];
scanf("%u %u", &is, &in);
for(i = 0; i < is; i++) {
tomb[i] = in;
}
do {
c = 0;
for(i = 0; i < is; i++) {
if(tomb[i] == 0) continue;
for(j = i + 1; j < is; j++) {
if(tomb[j] == 0) continue;
if(tomb[i] == tomb[j]) {
c = 1;
if(tomb[i] % 2 == 0) {
tomb[i] = tomb[i] / 2;
tomb[j] = 0;
} else {
tomb[i] = (tomb[i] + 1) / 2;
tomb[j] = tomb[j] * (tomb[j] + 1) / 2;
}
}
}
}
} while(c);
for(i = 0; i < is; i++) {
if (tomb[i] == 0) continue;
printf("1 / %u\n", tomb[i]);
}
getch();
}