C长整型数中各位上为奇数的数依次取出构成新数.

 时间:2026-02-12 03:04:17

1、打开Dev-C++

C长整型数中各位上为奇数的数依次取出构成新数.

2、写好头函数

#include<stdio.h>

C长整型数中各位上为奇数的数依次取出构成新数.

3、写好主函数

C长整型数中各位上为奇数的数依次取出构成新数.

4、主要代码

每次求余的数存放在d中,if判断d是否是奇数如果是就保存在t中,不是就不保存在t中。

int d;

long sl=1;

*t= 0;

while(s>0) 

{

    d=s%10;

    if (d%2 == 1) 

    {

        *t = d * sl + *t;

        sl *= 10;

    }

    s /= 10;

}

C长整型数中各位上为奇数的数依次取出构成新数.

5、完整代码

#include<stdio.h>

void fun(long s,long *t)

{

    int d;

    long sl=1;

    *t= 0;

    while(s>0) 

    {

        d=s%10;

        if (d%2 == 1) 

        {

            *t = d * sl + *t;

            sl *= 10;

        }

        s /= 10;

    }

}

void main() 

{

    long s,t;

    printf("\nPlease enter s:");

    scanf("%ld", &s);

    fun(s, &t);

    printf("The result is: %ld\n", t);

}

C长整型数中各位上为奇数的数依次取出构成新数.

6、结果如下图

C长整型数中各位上为奇数的数依次取出构成新数.

  • 圆盘的转动惯量怎么求,给出过程
  • 保守力做正功时,系统内相应的势能增加还是减少
  • 曲面积分的几何意义是什么
  • 如何交换积分次序
  • 线性代数p-1ap怎么求?
  • 热门搜索
    朱瞻基为什么英年早逝 微信夜间模式怎么设置 广州为什么叫羊城 火的笔顺怎么写 契税怎么算 意外怀孕怎么办 脖子上有个包块怎么回事 怎么煮面 床笠的做法 under怎么读