鱼C论坛

 找回密码
 立即注册
查看: 2676|回复: 11

两道编程题 请高手赐教

[复制链接]
回帖奖励 25 鱼币 回复本帖可获得 5 鱼币奖励! 每人限 1 次(中奖概率 80%)
发表于 2012-6-15 13:16:55 | 显示全部楼层

回帖奖励 +5 鱼币

1.
  1. #include <stdio.h>

  2. int GetNum( const char* msg );
  3. int Validtae( int a, int b );
  4. void Output( int num );
  5. int main(void){
  6.         int a,b;
  7.         a = GetNum("Input a:");
  8.         b = GetNum("Input b:");
  9.         if( Validtae( a,b ) ) {
  10.                 Output( a*a+b*b );
  11.         }
  12.         return 0;
  13. }

  14. int GetNum( const char* msg ) {
  15.         int result;
  16.         printf(msg);
  17.         scanf("%d",&result);
  18.         return result;
  19. }

  20. int Validtae( int a, int b ) {
  21.         return a*a+b*b>100;
  22. }

  23. void Output( int num ) {
  24.         printf("%d\n",num/100%10);
  25. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-6-15 13:25:22 | 显示全部楼层
本帖最后由 仰望天上的光 于 2012-6-15 13:27 编辑

2.

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>

  4. const char* GetStr();
  5. int IsPalidrome( const char* pstr );
  6. int main(void){
  7. const char* pstr = GetStr();
  8. printf("%s\n", IsPalidrome( pstr )?"Is Palidrome":"No Palidrome");
  9. return 0;
  10. }
  11. const char* GetStr() {
  12. static char result[100];
  13. printf("Input a string:");
  14. scanf("%s", result);
  15. return result;
  16. }
  17. int IsPalidrome( const char* pstr ) {
  18. const char* begin, *end;
  19. for( begin = pstr, end = pstr+strlen(pstr)-1 ;
  20.             begin<end; ++begin, --end ){
  21.   if( tolower(*begin) != tolower(*end) )
  22.    return 0;
  23. }
  24. return 1;
  25. }
复制代码

评分

参与人数 1鱼币 +3 收起 理由
嗜血灵异狂 + 3 赞一个!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-13 03:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表