fork download
  1. #include <math.h>
  2.  
  3. int main() {
  4. int a[33];
  5. int i, j, count = 0, x;
  6. a[0] = 2;
  7. a[1] = -1;
  8. for (i = 2; i <= 32; i++) {
  9. a[i] = -a[i - 1] + a[i - 2];
  10. }
  11. for (i = 0; i <= 32; i++) {
  12. if (a[i] > 1) {
  13. x = 1;
  14. for (j = 2; j <= sqrt(a[i]); j++) {
  15. if (a[i] % j == 0) {
  16. x = 0;
  17. break;
  18. }
  19. }
  20. if (x=1) {
  21. count++;
  22.  
  23. }
  24. }
  25. }
  26.  
  27. printf("a[0] から a[32] までのうち、正の素数の個数は %d 個です。\n", count);
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
a[0] から a[32] までのうち、正の素数の個数は 17 個です。