I.Ren |
|
| Dopo vedo di farlo in c : D Edit: fatto. CODICE #include <stdio.h> #include <stdlib.h> #include <string.h>
typedef enum {true,false} bool;
bool n_pari(int num); bool n_primo(int num); bool n_palindromo(int num);
int main() { int n=0; while (1==1) { if (n_pari(n)==true && n_primo(n) == true && n_palindromo(n) == true) { break; } n++; } printf("Il primo numero trovato e': %d",n); return 0; }
bool n_pari(int num) { if (num%2 == 0) return true; else return false; }
bool n_primo(int num) { int pos = (num+1)/2; while (pos > 1) { if (num % pos == 0 && pos != num && pos != 1) return false; pos--; } return true; }
bool n_palindromo(int num) { char to_str[4096]; char *buff = NULL; itoa(num,to_str,10); buff = realloc(buff,strlen(to_str)+1*sizeof(char)); strcpy(buff,to_str); strrev(buff); if (strcmp(to_str,buff) == 0) return true; else return false; free(buff); } master: non vi piaciono i spoiler vero xD Edited by xMasteRx - 2/4/2011, 20:05
|
| |