ProgrammingHardCognizant GenC · C · Advanced

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int isPrime(int n) { if (n < 2) return 0; for (int i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; } int main(void) { int c = 0; for (int i = 2; i <= 20; i++) if (isPrime(i)) c++; printf("%d", c); return 0; }

  1. A. 8
  2. B. 6
  3. C. 9
  4. D. 7

Correct answer: A. 8

Primes from 2 to 20 are 2,3,5,7,11,13,17,19: eight of them.

More C Programming questions

Exams that ask this topic