从1输出n位数字

#include <iostream>
#include <cstdio>
using namespace std;
int IsEnd(int *number,int len)
{
     if(number==NULL || len<=0) return NULL;
    for(int i=0;i<len;i++)
        if(number[i]!=9)
        return 0;
    return 1;
}
int *numberAdd1(int *number,int len)
{
    if(number==NULL || len<=0) return NULL;

    int jinwei=1;
    for(int i=len-1;i>=0;i--)
    {
        int one=number[i]+jinwei;
        number[i]=one%10;
        jinwei=one/10;

    }
    /*for(int i=0;i<len;i++)
        printf("%d",number[i]);
    printf("\n");*/
    return number;
}
void PrintNum(int *number,int len)
{
    if(number==NULL || len<=0) return ;
    int i=0;
    while(number[i]==0)
        i++;
    for(;i<len;i++)
        printf("%d",number[i]);
    printf("\n");
}
int main()
{
    int number[]={0,0,0,0,0};
    int *number1=number;
    while(!IsEnd(number1,5))
    {
        number1=numberAdd1(number1,5);
        PrintNum(number1,5);
    }

    return 0;
}

posted on 2014-07-02 22:17  XiaoFei Wang  阅读(141)  评论(0编辑  收藏  举报

导航