[C] Re: c语言 四位数 黑洞数 →→→→→进入此内容的聊天室

来自 Colorant Meerkat, 2024-03-21, 写在 C, 查看 15 次. 这张便签是回复 c语言 四位数 黑洞数 来自 Perl Goat - 对比版本
URL http://www.code666.cn/view/3fe017b1
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int isPalindrome(int num) {
  6.     char str[10];
  7.     sprintf(str, "%d", num);
  8.     int len = strlen(str);
  9.     for (int i = 0; i < len / 2; i++) {
  10.         if (str[i] != str[len - 1 - i]) {
  11.             return 0;
  12.         }
  13.     }
  14.     return 1;
  15. }
  16.  
  17. int main() {
  18.     int N;
  19.     printf("Enter a positive integer: ");
  20.     scanf("%d", &N);
  21.  
  22.     if (isPalindrome(N)) {
  23.         printf("%d is a black hole number.\n", N);
  24.     } else {
  25.         printf("%d is not a black hole number.\n", N);
  26.     }
  27.  
  28.     return 0;
  29. }

回复 "Re: c语言 四位数 黑洞数"

这儿你可以回复上面这条便签

captcha