This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- –- 普通の再帰-- -} | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- –- 普通の再帰-- -} | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 普通の再帰 | |
(define (factorial n) | |
(if (= n 1) | |
1 | |
(* n (factorial (- n 1))))) | |
;;; 末尾再帰 | |
(define (factorial n) | |
(fact-iter 1 1 n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 現在は修正されています | |
前: 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(void) | |
{ | |
char keyword[11]; | |
char word[32]; | |
int counter = 0; | |
memset(keyword, '\0', sizeof(keyword)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 末尾再帰 tailRecursion.c | |
再帰的な関数recurを徐々に非再帰的にしていく | |
*/ | |
#include <stdio.h> | |
// 真に再帰的な関数recur | |
void recur(int n) | |
{ | |
if (n > 0) { | |
recur(n - 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); // スタック初期化の関数 |