2014/02/26

Enable Numpad in PuTTY

Change settings -> Terminal -> Features -> Disable application keypad mode

see the picture below:


2014/02/16

[C]方向鍵輸入判斷

#include <stdio.h>
#include <conio.h>

int main()
{
    char ch1, ch2;
    while(ch1 = getch())
    {
        if(ch1 == -32)
{
            ch2 = getch();
         
            if(ch2 == 72)
                printf("up key press\n");
            if(ch2 == 75)
                printf("left key press\n");
            if(ch2 == 77)
                printf("right key press\n");
            if(ch2 == 80)
                printf("down key press\n");
    }
    }
    return 0;
}

2013/12/11

[C] 組合

剛好用到求組合數
就順便紀錄下來

#include <stdio.h>
#include <conio.h>

int main()
{
int n,k,ans=1;
printf("n = ");
scanf("%d",&n);
printf("k = ");
scanf("%d",&k);
if(n-k < k)
k = n-k;
for(int i=0; i<k; i++)
{
ans = ans*n/(i+1);
n--;
}
printf("%d",ans);
getch();
return 0;
}

2013/11/09

[C]二進位轉十進位

#include <stdio.h>
#include <conio.h>

int main()
{
int n,c=1,Dec=0;

scanf("%d",&n);
while(n>0)
{
Dec += (n%10)*c;
c= c*2;
n/=10;
}

printf("%d",Dec);
getch();
         return(0);
}

[C]十進位轉二進位

#include <stdio.h>
#include <conio.h>

int main()
{
        int n,Bin=0,c=1;

scanf("%d",&n);
while(n>0)
{
Bin += (n%2)*c;
c *= 10;
n /= 2;
}

        printf("%d",Bin);
        getch();
        return(0);
}