-
-
Save pastak/5977005 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //フィボナッチ数かつ素数を小さいのから10個出力 | |
| #include <stdio.h> | |
| int main(void){ | |
| int count = 0; | |
| int tmp[2] = {1,1}; | |
| int n,i,j; | |
| int is_prime; | |
| for(i = 0;count < 10;i++){ | |
| //フィボナッチ数を求める | |
| n = tmp[0] + tmp[1]; | |
| tmp[i%2] = n; | |
| //素数か判定 | |
| is_prime = 1; | |
| for(j = 2;j < n/2;j++){ | |
| //2からn/2までの数で割って1つでも割り切れなかったら素数 | |
| if(n % j == 0){ | |
| is_prime = 0; | |
| } | |
| } | |
| //素数ならカウンタを進めて出力 | |
| if(is_prime){ | |
| count++; | |
| printf("%d\n",n); | |
| } | |
| /* | |
| else{ | |
| printf("(%d)\n",n); | |
| } | |
| */ | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment