Count Negative Elements

A list of number is given. Make a program which counts the no of negative elements using array inc.

Questions by abhi2029

Showing Answers 1 - 3 of 3 Answers

trying

  • Oct 27th, 2010
 

void main()
{
int size, *array;
printf("enter the size of the array");
scanf("%d",size);

if(array=(int*)malloc(size*sizeof(int)))
{
printf("malloc failedn");
exit(1);
}

int i,count=0;

for(i=0;i<size;i++)
{
scanf("%d",array[i]);
}

for(i=0;i<size;i++)
{
if(array[i]<0)
{
count++;
}
}

printf("Count of negative elements in the array is : %d",count);
system("pause");
}


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions