输入一个正整数repeat (0输入一个整数,从高位开始逐位输出它的各位数字。
输出语句:printf("%-2d", digit);
例:括号内是说明
输入
3   (repeat=3)
123456
-600
8
输出
1 2 3 4 5 6
6 0 0
8

#include <stdio.h>
int main( )
{
  int ri, repeat;
  int digit;
  long in, temp, pow;

  scanf("%d", &repeat);
  for(ri=1; ri<=repeat; ri++){
    scanf("%ld", &in);
  if(in<0)
    in=-in;
  temp=in;
  pow=1;
  while(temp!=0){
    temp=temp/10;
    pow=pow*10;
  }
  pow=pow/10;
  while(pow!=0){
    digit=in/pow;
    printf("%-2d", digit);
    in=in%pow;
    pow=pow/10;
  }
    printf("\n");
  }
}
Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(273)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember