zoukankan      html  css  js  c++  java
  • 小程序_数字逆序

    #include <stdio.h>

    /****************************************************************
    题目:给一个不多于5位的正整数,
    要求:
    一、求它是几位数,
    二、逆序打印出各位数字。
    1. 程序分析:学会分解出每一位数,如下解释:
    *****************************************************************/

    void main(void)
    {
    int temp[5] = {0};
    int num = 0;
    int digit = 1;
    int count = 0;

    while(1)
    {
    printf("Pls input the num ");
    scanf("%d",&num);

    digit = 1;
    if(0>num||100000<num)
    {
    printf("Number is out of range! ");
    fflush(stdin);
    continue;
    }

    temp[4] = (num/10000)%10;
    temp[3] = (num/1000)%10;
    temp[2] = (num/100)%10;
    temp[1] = (num/10)%10;
    temp[0] = num%10;

    for(count = 4; count >= 0; count--)
    {
    if(0 !=temp[count])
    {
    digit = count+1;
    break;
    }
    }

    printf("It is a [%d] digit ",digit);
    for(count = 0 ; count< digit ; count++ )
    {
    printf("%d",temp[count]);
    }

    printf(" ");

    fflush(stdin);

    }

    }

    /***************** 今天为了更好的明天 ******************/
  • 相关阅读:
    Beta冲刺 5
    Beta冲刺 4
    Beta冲刺 3
    Beta冲刺 2
    Beta冲刺 1
    项目评测博客
    Beta冲刺前准备
    Alpha 冲刺11——总结
    Alpha冲刺10
    Alpha冲刺9
  • 原文地址:https://www.cnblogs.com/cheng-amy/p/5805747.html
Copyright © 2011-2022 走看看