Last active
April 8, 2018 19:46
-
-
Save ander94lakx/3732c36634544c6991ef9a06d90f39c8 to your computer and use it in GitHub Desktop.
REKURTSIBITATEA
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 _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <string.h> | |
void bistaratuAlderantziz(char *str); | |
int main() | |
{ | |
char hitza[15]; | |
printf("Esaldi bat sartu:\n"); | |
scanf("%s", hitza); | |
printf("%s\n", hitza); | |
bistaratuAlderantziz(hitza); | |
return 0; | |
} | |
void bistaratuAlderantziz(char *str) | |
{ | |
if (strlen(str) == 0) | |
{ | |
return; | |
} | |
else if (strlen(str) == 1) | |
{ | |
printf("%c", str[0]); | |
} | |
else | |
{ | |
bistaratuAlderantziz(str + 1); | |
printf("%c", str[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
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
int Konbinatorioa(int n, int k); | |
int main() | |
{ | |
int n, k; | |
printf("n eta k sartu: "); | |
scanf("%d%d", &n, &k); | |
printf("Zenbaki konbinatorioa: \n", Konbinatorioa(n, k)); | |
printf("%d\n", Konbinatorioa(n, k)); | |
getchar(); | |
return 0; | |
} | |
int Konbinatorioa(int n, int k) | |
{ | |
if (k == 0 || k == n) | |
return 1; | |
return Konbinatorioa(n - 1, k - 1) + Konbinatorioa(n - 1, k); | |
} |
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 _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <string.h> | |
void hanoi(int, char, char, char); | |
int main() | |
{ | |
int num; | |
printf("Enter the number of disks: "); | |
scanf("%d", &num); | |
printf("Hanoi dorreen mugimendu sekuentzia:\n"); | |
hanoi(num, 'A', 'C', 'B'); | |
return 0; | |
} | |
void hanoi(int num, char dorretik, char dorrera, char aux) | |
{ | |
if (num == 1) | |
{ | |
printf("Mugitu diska 1 dorre %c-ti dorre %c-ra\n", dorretik, dorrera); | |
return; | |
} | |
hanoi(num - 1, dorretik, aux, dorrera); | |
printf("Mugitu diska 1 dorre %c-ti dorre %c-ra\n", num, dorretik, dorrera); | |
hanoi(num - 1, aux, dorrera, dorretik); | |
} |
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 _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <string.h> | |
int nire_strlen(char *str); | |
int main() | |
{ | |
char hitza[15]; | |
printf("Esaldi bat sartu:\n"); | |
scanf("%s", hitza); | |
printf("%s\n", hitza); | |
printf("Luzera: %d\n", nire_strlen(hitza)); | |
return 0; | |
} | |
int nire_strlen(char *str) | |
{ | |
if (*str == '\0') | |
{ | |
return 0; | |
} | |
else | |
{ | |
return nire_strlen(str + 1) + 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
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <string.h> | |
int palindromoaDa(char *hitza, int i); | |
int palindromoaDa2(int hasiera, int amaiera, char *hitza); | |
int main() | |
{ | |
char hitza[15]; | |
printf("Esaldi bat sartu:\n"); | |
scanf("%s", hitza); | |
if (palindromoaDa(hitza, 0)) | |
{ | |
printf("Palindromoa da\n"); | |
} | |
else | |
{ | |
printf("Ez da palindromoa\n"); | |
} | |
if (palindromoaDa2(0, strlen(hitza) - 1, hitza)) | |
{ | |
printf("Palindromoa da\n"); | |
} | |
else | |
{ | |
printf("Ez da palindromoa\n"); | |
} | |
return 0; | |
} | |
int palindromoaDa(char *hitza, int i) | |
{ | |
int len = strlen(hitza) - (i + 1); | |
if (hitza[i] == hitza[len]) | |
{ | |
if (i + 1 == len || i == len) | |
{ | |
return 1; | |
} | |
palindromoaDa(hitza, i + 1); | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
int palindromoaDa2(int hasiera, int amaiera, char *hitza) | |
{ | |
if (hitza[hasiera] != hitza[amaiera]) | |
{ | |
return 0; | |
} | |
else if (hasiera == amaiera) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return palindromoaDa2(++hasiera, --amaiera, hitza); | |
} | |
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
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <string.h> | |
void permutazioak(int*, int, int); | |
void swap(int*, int*); | |
int main() | |
{ | |
int zenbakia; | |
char str[128]; | |
int zenbaki_zerrenda[100]; | |
int luzera = 0; | |
do { | |
printf("Sartu zenbaki bat:\n"); | |
fgets(str, 128, stdin); | |
sscanf(str, "%d", &zenbakia); | |
if (zenbakia != 0) | |
{ | |
zenbaki_zerrenda[luzera++] = zenbakia; | |
} | |
} while (zenbakia != 0); | |
permutazioak(zenbaki_zerrenda, 0, luzera); | |
getchar(); | |
return 0; | |
} | |
void permutazioak(int *zenbakiak, int i, int dim) | |
{ | |
if (i == dim - 1) | |
{ | |
for (int i = 0; i < dim; i++) { | |
printf("%d ", zenbakiak[i]); | |
} | |
printf("\n"); | |
} | |
else | |
{ | |
for (int j = i; j < dim; j++) { | |
swap(zenbakiak + i, zenbakiak + j); | |
permutazioak(zenbakiak, i + 1, dim); | |
swap(zenbakiak + i, zenbakiak + j); | |
} | |
} | |
} | |
void swap(int *i, int *j) | |
{ | |
int t = *i; | |
*i = *j; | |
*j = t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment