Need help Thank you The following program is used to read 10

Need help. Thank you
The following program is used to read 10 integer numbers from user, store them in an array and use a function to check if the array has a negative value.

Solution

Line which are incorrect:

2,6,7,10,15,18,19,21.

Line 2:

define N 10 to

#define N 10

Line 6:

for(i = 0;i < = N;i++){ where i is not declared.

Line 7:

scanf(%lf,&a[i]); we must have to read integer so use it as scanf(\"%d\",&a[i]);

Line 10:

if(hasZero(a)) printf(\"Array has a value 0\"); we must have to pass the length as second parameter

if(hasZero(a,N)) printf(\"Array has a value 0\");

Line 15:

BOOL hasZero(int[] arr,int length){ to returrn bool we must have to use

#include <stdbool.h> and change to

bool hasZero(int arr[],int length){

aslo we must to declare protoType before main

bool hasZero(int arr[],int length);

Line 18:

if(arr[i] = 0) change that to

if(arr[k] = 0)

Line 19:

return TRUE; change that to  return true;

Line 21:

return FALSE; change that to return false;

Here is correct code:

#include <stdio.h>
#include <stdbool.h>
#define N 10
bool hasZero(int arr[],int length);
int main(void){
int a[N],i=0;
for(i = 0;i <= N;i++){
scanf(\"%d\",&a[i]);
}
  
if(hasZero(a,N)) printf(\"Array has a value 0\");
return 1;

}

bool hasZero(int arr[],int length){
int k=0;
for(k=0;k<length;k++){
if(arr[k] == 0)
return true;
}
return false;
}

Need help. Thank you The following program is used to read 10 integer numbers from user, store them in an array and use a function to check if the array has a n
Need help. Thank you The following program is used to read 10 integer numbers from user, store them in an array and use a function to check if the array has a n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site