Skip to content

Instantly share code, notes, and snippets.

View chomado's full-sized avatar
🎀
Working

ちょまど | Madoka Chiyoda chomado

🎀
Working
View GitHub Profile
{- –- 普通の再帰-- -}
my_soap :: Integer -> Integer
my_soap 0 = 0
my_soap n = my_soap (n-1) + n
{- –- 末尾再帰-- -}
my_soap_iter :: Integer -> Integer
my_soap_iter x = my_soap_iter2 x 0
my_soap_iter2 :: Integer -> Integer -> Integer
{- –- 普通の再帰-- -}
my_mul :: Integer -> Integer -> Integer
my_mul m 1 = m
my_mul m n = my_mul m (n - 1) + m
{- –- 末尾再帰-- -}
my_mul_iter :: Integer -> Integer -> Integer
my_mul_iter x y = iter x y x
where
iter :: Integer -> Integer -> Integer -> Integer
;;; 普通の再帰
(define (factorial n)
(if (= n 1)
1
(* n (factorial (- n 1)))))
;;; 末尾再帰
(define (factorial n)
(fact-iter 1 1 n))
/* 現在は修正されています
前: scanf("%c %d", &mark, &num);
後: scanf(" %c %d", &mark, &num);
*/
#include <stdio.h>
void check(int);
void print(void);
int mark_to_id(char mark);
/************ メイン関数 ***********/
int main(void)
#include <stdio.h>
char grading(int, int, int);
/***** メイン関数 ********/
int main(void)
{
int m, f, r;
while (scanf("%d %d %d", &m, &f, &r), ~m||~f||~r) {
printf("%c\n", grading(m, f, r));
}
return 0;
#include <stdio.h>
int check(int, int, int, int);
int solve(int, int);
/***** メイン関数 *****/
int main(void)
{
int n, sum;
while (scanf("%d %d", &n, &sum), n||sum) {
printf("%d\n", solve(n, sum));
}
#include <stdio.h>
int check(char c)
{
if ('A'<= c && c <='Z') return 1;
else if ('a'<=c && c<='z') return 0;
else return 2;
}
/** メイン関数 **/
int main(void)
{
#include <stdio.h>
#include <string.h>
int main(void)
{
char keyword[11];
char word[32];
int counter = 0;
memset(keyword, '\0', sizeof(keyword));
@chomado
chomado / tailRecursion.c
Created July 16, 2014 03:55
末尾再帰
/* 末尾再帰 tailRecursion.c
再帰的な関数recurを徐々に非再帰的にしていく
*/
#include <stdio.h>
// 真に再帰的な関数recur
void recur(int n)
{
if (n > 0) {
recur(n - 1);
@chomado
chomado / stackByArray.c
Last active August 29, 2015 14:04
Stack実装 配列を使って. (だから要素数は有限, 静的)
#include <stdio.h>
#include <stdlib.h>
#define MAX 256
/* must keep the length of the stack (in the array implementation) */
typedef struct {
size_t size; // スタックのサイズ(要素数)
int items[MAX]; // スタック本体みたいな感じ.要素が入る配列
} Stack;
void init (Stack *stckPtr); // スタック初期化の関数