-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprod_input.c
More file actions
68 lines (59 loc) · 691 Bytes
/
prod_input.c
File metadata and controls
68 lines (59 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
// Input data generator for CS 341 PA2. BKR
int
isPrime( int n )
{
int i;
for ( i = 2 ; i*i <= n ; i++ )
{
if ( n % i == 0 )
{
return 0;
}
}
return 1;
}
static int
isfib( int i )
{
static int x = 1, y = 1;
int z;
if ( i == y )
{
z = x + y;
x = y;
y = z;
return 1;
}
else
{
return 0;
}
}
is3or5( int i )
{
if ( i % 3 == 0 ) return 1;
else if ( i % 5 == 0 ) return 1;
else return 0;
}
int
main()
{
int i;
for ( i = 0 ;; i++ )
{
if ( isPrime( i ) )
{
printf( "red %d\n", i );
}
if ( isfib( i ) )
{
printf( "green %d\n", i );
}
if ( is3or5( i ) )
{
printf( "blue %d\n", i );
}
}
return 0;
}