遞迴_完全平方數
user_3763047219
c_cpp
3 years ago
666 B
8
Indexable
#include <stdbool.h>
bool rangePerfectSquare(int, int, int);
bool rangePerfectSquare(int left, int right, int target) {
if (left * left < target && left+1<right) {
rangePerfectSquare(left + 1, right, target);
}
else if (left * left == target) {
return 1;
}
else if (left * left > target) {
return 0;
}
}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main() {
int a;
scanf("%d", &a);
bool ans = rangePerfectSquare(1, INT_MAX, a);
if (ans) {
printf("true");
}
else {
printf("false");
}
printf("\n");
return 0;
}Editor is loading...