[ create a new paste ] login | about

Link: http://codepad.org/iXNGAvFD    [ raw code | output | fork ]

C, pasted on Sep 24:
#include <stdio.h>
#include <stdlib.h>


main()
{
    int a[]={0,1,2,3,4,5,6,7,8,9,0};
    int b[11];
    int trq_tbl_shift=-13;
    int i;
    printf("シフト%d\n", trq_tbl_shift);
    for(i=0; i<11; i++) printf("%d", a[i]);
    printf("\n");
    printf("%d\n", trq_tbl_shift);
    
    if (trq_tbl_shift <= 0)
    {
        if (abs(trq_tbl_shift) > 11-1) trq_tbl_shift = (11-1) + trq_tbl_shift;
        for (i=0; i<(11-1); i++)
        {
            if ( (i+trq_tbl_shift) >= 0 )
            {
                b[i+trq_tbl_shift] = a[i];
            }
            else
            {
                 b[(11-1) + i+trq_tbl_shift] = a[i];
            }   
        }
    } else {
        if (trq_tbl_shift > (11-1)) trq_tbl_shift = trq_tbl_shift - (11-1);
        for (i=0; i<(11-1); i++)
        {
            if ( (i+trq_tbl_shift) < (11-1) )
            {
                b[i+trq_tbl_shift] = a[i];
            }
            else
            {
                 b[(i+trq_tbl_shift) - (11-1)] = a[i];
            }
        }  
    }
    
    /*
    for (i=0; i<(11-1); i++)
    {
        if (trq_tbl_shift <= 0)
        {
            if ( (i+trq_tbl_shift) >= 0 )
            {
                b[i+trq_tbl_shift] = a[i];
            }
            else
            {
                 b[(11-1) + i+trq_tbl_shift] = a[i];
            }
        } else {
            if ( (i+trq_tbl_shift) < (11-1) )
            {
                b[i+trq_tbl_shift] = a[i];
            }
            else
            {
                 b[(i+trq_tbl_shift) - (11-1)] = a[i];
            }
        }
        
    }
    */

    b[11-1] = b[0];
    
    if(trq_tbl_shift >= 0)
        printf("%d遅れ", trq_tbl_shift);
    else
        printf("%d進み", -1*trq_tbl_shift);
    for(i=0; i<11; i++) printf("%d", b[i]);
}


Output:
1
2
3
4
シフト-13
01234567890
-13
3進み34567890123


Create a new paste based on this one


Comments: