Question
Question!
.Use make -f Makefile to compile the three problem C programs Within Problem1.c we will use gdb ions . Within Problem2.c we will use assert then turn off . Within Problem3.c we will use gdb again and I will begin but you will need to finish . Assignment: run gdb and file Problem3.o ve odisplay val.cnt, out, tot (variables) o Set breakpoints on main and the line that throws the segmentation fault o Show the screenshot of the gdbsession when it receives the signal o (1)what is the problem? (2)What is the signal received (3)how could you fix this code?
Problem 1.c
media%2F9b2%2F9b2d2a03-07df-424b-ac0c-f0
Problem 2.c
media%2Fd5b%2Fd5b73d26-fe34-4a36-87aa-1c
Problem 3.c
media%2Ff44%2Ff44442dd-4821-472a-a3dc-5a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

hi, please go threw output and code.

solution.

#include <stdio.h>

int main()

{

int out =0, tot = 0, cnt = 0;

int val[] = {5,54,76,91,35,27,45,15,99,0};

while(cnt < 10)

{

out = val[cnt];

if(out > 0) // put here condition so that it will not became devide by 0

tot = tot + 0xffffffff/out;

cnt++;

}

printf("\n Total = [%d]\n",tot);

return 0;

}

- problem is at line 9 : tot = tot + 0xffffffff/out; and at line 5.int val[] = {5,54,76,91,35,27,45,15,99,0};

last elemenet of val is 0. so when out is geting 0 then it became devide by zero.

so it will give segmentation fault and will recive signal.

- signal is SIGFPE, Arithmetic exception.

- we can fix by putting if condition before deviding.we make sure it should be positive value.

Add a comment
Know the answer?
Add Answer to:
Question! Problem 1.c Problem 2.c Problem 3.c .Use make -f Makefile to compile the three problem...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT