Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 4 Correct errors in program . ( 1 0 points in total): 1) ( 5 points) The fo

ID: 3740680 • Letter: P

Question

Part

4

Correct

errors in program

.

(

1

0

points in total):

1)

(

5

points)

The following program is used to

display numbers between two intervals

.

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

#include stdio.h

#define true 1

#define false 0

void prime(int low, int high){

int i =0, flag=0;

printf("Prime numbers between %d and %d are: ", low, high);

while (low < high)

{

flag = false;

for(i = 0

; i <= low/2; ++i)

{

if(low % i == 0)

{

flag = true;

break;

}

}

if (flag ==

true

)

print

f("%d ", low);

++low;

}

printf("

n");

}

int main()

{

int low, high;

printf("Enter two numbers(intervals): ");

scanf("%d %d", low,

high);

prime.

prime(low,high);

return 0;

}

Which line

(s)

is

(are)

incorrect?

And how to correct it

(them)

? Please write down your

correction

for that

line (those lines)

Explanation / Answer

If you have any problems with the answer or want me to edit the answer, just let me know in the comments and I will try to get on to it as soon as possible. Do give a positive rating if you think this answer helped.

Errors

1. #include stdio.h must be like #include<stdio.h>

2. We need to print numbers between two intervals so, we don't need the prime method for it. And also is error in prime method, we can simply call prime method there is no need to call it with prime.prime

3. Don't use unnecessary loop u can get result with single while loop. There is no requirement for checks also.

4. Always take input with &var_name otherwise it gives segmentation fault.

// correct code

#include <stdio.h>

#define true 1

#define false 0

void prime(int low, int high){

// int i =0; no requirement of flag=0 ;

printf("Numbers between %d and %d are: ", low, high);

while (low <= high){

//flag = false;

// this for loop is not required as we want to

// print number between two values

/*for(i = 0; i <= low/2; ++i){

if(low % i == 0){

flag = true;

break;

  

}

  

}

if (flag == true)*/

printf("%d ", low);

low++;

  

}

printf(" ");

  

}

int main()

{

int low, high;

printf("Enter two numbers(intervals): ");

scanf("%d %d", &low,&high);

prime(low,high);

  

return 0;

}