Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 2138163b authored by Rachel D Frenkel's avatar Rachel D Frenkel
Browse files

homework 11

parent f6409bf9
# EECS 201 HW 11
uniqname: rfrenkel
## Question 1
``` 1
The only cases that this actually works is 0-2 because those is_prime[j] do == 1 because they are hardcoded in.
In all other cases, the array will set the value = 0 therefore the while(true) loop will never return and therefore
will loop forever, or until it reaches a value = MAX_PRIMES where it will seg fault.
```
## Question 2
``` 2
break 33
s
break 15
s
s
s
s
s
c ... (until you see that it never enters the if statement of k % j == 0)
finish
```
## Question 3
``` 3
-bash-4.2$ gdb -q ./prime
Reading symbols from /home/rfrenkel/Desktop/201/hw11/debugging-basics/prime...done.
(gdb) break 33
Breakpoint 1 at 0x400606: file prime.c, line 33.
(gdb) run
Starting program: /home/rfrenkel/Desktop/201/hw11/debugging-basics/./prime
Find all prime numbers between 3 and ?
10
Breakpoint 1, main () at prime.c:33
33 check_prime(N);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7_6.3.x86_64
(gdb) c
Continuing.
3 is a prime
Breakpoint 1, main () at prime.c:33
33 check_prime(N);
(gdb) c
Continuing.
5 is a prime
Breakpoint 1, main () at prime.c:33
33 check_prime(N);
(gdb) c
Continuing.
7 is a prime
Breakpoint 1, main () at prime.c:33
33 check_prime(N);
(gdb) s
check_prime (k=9) at check.c:13
13 for (j=2; j*j <= k; j++) {
(gdb) s
14 if (is_prime[j] == 1)
(gdb) s
15 if (k % j == 0) {
(gdb) s
19 j++;
(gdb) s
13 for (j=2; j*j <= k; j++) {
(gdb) s
23 is_prime[k] = 1;
(gdb) finish
Run till exit from #0 check_prime (k=9) at check.c:23
main () at prime.c:34
34 if (is_prime[N])
Because we ++j at the end of the loop and within the for statement, j skips the value of 3 and runs 2*2 where 9 % 4 != 0 and 4*4 where 16 > 9,
therefore exiting the loop. For this to run properly there should only be a ++j in the for loop statement and not further into the code.
```
## Question 4
``` 4
3 does not have the unconditional jump warning because that warning happens in the for loop with unitialized values for is_prime[j].
```
## Question 5
``` 5
j = 2
```
## Question 6
``` 6
undefined because we did not initialize anything to 0.
```
## Question 7
``` 7
is_prime[2] = 1;
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment