
Ab L.
asked 10/16/17I need help with this C programming question. Please. :(
int main()
{
int n;
int pos;
int odd;
int i;
for(i=0; i<16 ;i++)
{
scanf("%d", n);
if(n>0)
{
pos++;
}
if(n == 0)
{
odd++;
}
return 0;
}
}
1 Expert Answer

Patrick B. answered 03/10/19
Math and computer tutor/teacher
#include <stdio.h>
int main()
{
int numPos=0;
int numNeg=0;
int numOdd=0;
int numEven=0;
int iLoop;
int num;
for (iLoop=0; iLoop<16; iLoop++)
{
printf(" Please input an integer :>"); /* leave a prompt message for the user */
scanf("%d",&num); /* ALWAYS pass the address of the var when using scanf */
if (num>0) { numPos++; }
if (num<0) { numNeg++; }
if ((num%2)==0)
{
numEven++; /* even numbers divide by 2, using the MOD function */
}
else
{
numOdd++;
}
}
printf(" # of positives : %d \n"
" # of negatives : %d \n"
" # of evens : %d \n"
" # of odds : %d \n",
numPos, numNeg, numEven, numOdd
);
return 0;
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Tony J.
10/16/17