2009/06/10

gcd

自然数のgcd(最大公約数)をもとめる再帰関数を、goto文で置き換える。

[再帰バージョン]

int gcd(int x, int y){

 if(!y)
  return x;
 else
  return gcd(y, x%y);

}

[gotoバージョン]

int gcd(int x, int y){

 int z=1; //1が最小公倍数

 loop:

 if(!z)
 return x;
  else
   z=x%y;
   x=y;
   y=z;
   goto loop;
}

2009/06/04

ブログ再開します!

一発目。自己末尾再帰関数。processingで。

void setup()
{
noLoop();
}

void draw()
{
int val=1;
println(factorial(val,4));

}

int factorial(int temp, int n){

if(temp>0)
temp*=n;
else
println("error");

if(n-1==0){
return temp;
}
else{
return factorial(temp, n-1);
}
}

2009/03/20

久々の

投稿がこれですか。。情けなし。→しょこたん×ノートンのガジェット

それとしょこたんAIRをインストールしてみた。どうだろね=。カレンダーとかflvとかはありがたい。

About Me

自分の写真
目指せネイチャアプログラマ!Objective-C/Cocoa、web系スキルも絶賛習得中。Nature Interfaceに興味ありあり。
Powered By Blogger

Mitolog © 2008. Template by Dicas Blogger.

TOPへ