Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int countDigits(int x){
- int count = 0;
- while(x){
- x/=10;
- count++;
- }
- return count++;
- }
- int main(){
- int num,nums,numsDigs,mod,div,den,j;
- while(scanf("%d",&num),num){
- if(num<100){
- printf("%d\n",num);
- continue;
- }
- int digits = countDigits(num);
- int split = (digits%2==0?digits/2:digits/2+1);
- int space = (digits%2==0?digits-1:digits);
- int bound = (digits%2==0?-1:0);
- int n = (digits%2==0?0:-1);
- for(int i=1;i<=split;i++){
- mod = pow(10,(2*i+n));
- div = pow(10,digits-(digits/2+1)) / pow(10,i-1);
- nums = num/div%mod;
- numsDigs = countDigits(nums);
- for(j=1;j<=space-(2*(i-1));j++){
- printf(" ");
- }
- for(j=1;j<=2*i+n;j++){
- den = (numsDigs>1?pow(10,numsDigs-j):1);
- printf("%d ",nums/den%10);
- }
- printf("\n");
- }
- for(int i=digits-split;i>0;i--){
- mod = pow(10,(2*i+n));
- div = pow(10,digits-(digits/2+1)) / pow(10,i-1);
- nums = num/div%mod;
- numsDigs = countDigits(nums);
- for(j=1;j<=space-(2*(i-1));j++){
- printf(" ");
- }
- for(j=1;j<=2*i+n;j++){
- den = (numsDigs>1?pow(10,numsDigs-j):1);
- printf("%d ",nums/den%10);
- }
- printf("\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement