Question

Consider the array called myArray declared below t

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

Code: it works even if the elements in the array are changed

#include<stdio.h>
main()
{
// Array given in the question
int myArray[] = {-1,3,-9,9,33,-4,-5,100,4,-23};
// determine the length of the array
/* dividing total number of bytes occupied by array
with number of bytes per element gives number of elements*/
int len = sizeof(myArray)/sizeof(myArray[0]);
// initialize count to 0
int i, count = 0;
// loop over all the elements of array
for(i = 0; i<len; i++)
{
// if current element of array is greater than or equal to 0,
// increment count
if(myArray[i] >= 0)
count++;
}
// print the value of count
printf("Number of positive integers is %d\n", count);
}

Screenshot of code:

sample.c X # include<stdio. h> main () 2 // Array given in the question int myArray [ ] {-1,3,-9, 9, 33,-4,-5, 100,4,-23); /Output:

Laptop\Chegg filessample.exe Number of positive integers is 5 NLaptop Chegg files)

Add a comment
Know the answer?
Add Answer to:
Consider the array called myArray declared below that contains positive V and negative integers. Write a...
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
Active Questions
ADVERTISEMENT