We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc74dd8 commit 55433fbCopy full SHA for 55433fb
prog.7.4.c
@@ -0,0 +1,33 @@
1
+#include <stdio.h>
2
+#include <stdbool.h>
3
+
4
+// Modified program to generate prime numbers
5
6
+int main (void)
7
+{
8
+ int p, i, primes[50], primeIndex = 2;
9
+ bool isPrime;
10
11
+ primes[0] = 2;
12
+ primes[1] = 3;
13
14
+ for ( p = 5; p <= 50; p = p + 2 ) {
15
+ isPrime = true;
16
17
+ for ( i = 1; isPrime && p / primes[i] >= primes[i]; ++i )
18
+ if ( p % primes[i] == 0 )
19
+ isPrime = false;
20
21
+ if ( isPrime == true ) {
22
+ primes[primeIndex] = p;
23
+ ++primeIndex;
24
+ }
25
26
27
+ for ( i = 0; i < primeIndex; ++i )
28
+ printf ("%i ", primes[i]);
29
30
+ printf ("\n");
31
32
+ return 0;
33
+}
0 commit comments