BUPT-homework/semester1/pset5/5-matrix.c

33 lines
558 B
C
Raw Normal View History

2021-10-25 21:40:59 +08:00
#include <math.h>
#include <stdio.h>
// Function prototypes
int checkf(float f);
int main(void) {
// Initialize variables
float m, n;
scanf("%f%f", &m, &n);
int a;
float bf, cf;
for (a = 0; a <= (int)m; a++) {
cf = (float)a + (n / 2) - (m * 2);
if (checkf(cf) == 1) {
bf = ((n / 2) - m - cf * 2);
if (checkf(bf) == 1) {
printf("%i %i %i\n", a, (int)bf, (int)cf);
}
}
}
return 0;
}
int checkf(float f) {
if (floorf(f) == f && f >= 0) {
return 1; // True
} else {
return 0; // False
}
}