输入一个五位以内的正整数,(1)判断它是一个几位数;(2)请按序输出其各位数字;(3)逆序输出其各位数字。

/* 输入一个五位以内的正整数,(1)判断它是一个几位数;(2)请按序输出其各位数字;(3)逆序输出其各位数字。 
如输入:56439,输出:5位数 
           5,6,4,3,9 
           9,3,4,6,5
*/
 1#include<stdio.h>
  2 
  3 int a[5],b[5];
  4 void display(int i)
  5 {printf("the positive sort is:");
  6  int j=0;
  7  for(j=i;j>0;j--)
  8  printf("%d",a[j-1]);
  9  printf("\n");
 10 printf("the negative sort is:");
 11  for(j=0;j<i;j++)
 12   printf("%d",a[j]);
 13   printf("\n");
 14  
 15 }
 16 
 17 void main()
 18 {
 19 int num;
 20 printf("input your number:");
 21 scanf("%d",&num);
 22 if(num<0||num>99999) {printf("error!\n");}
 23 else{
 24 a[4]=num/10000;b[2]=num%10000;
 25 a[3]=b[2]/1000;b[1]=b[2]%1000;
 26 a[2]=b[1]/100;b[0]=b[1]%100;
 27 a[1]=b[0]/10;
 28 a[0]=b[0]%10;
 29 if(a[4]!=0)
 30    { printf("five\n");
 31     display(5);}
 32  else
 33     if(a[3]!=0)
 34     { printf("four\n");
 35       display(4);}
 36     else
 37        if(a[2]!=0)
 38          {printf("three\n");
 39          display(3);}
 40         else
 41           if (a[1]!=0)
 42               {printf("two\n");
 43               display(2);}
 44           else
 45              if(a[0]!=0)
 46                {   printf("one\n");
 47                   display(1);}
 48              else
 49                 printf("error!\n");
 50  }
 51 }
                                                        
发布了22 篇原创文章 · 获赞 4 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章