-
Odd/Even counter.
I have written a program to count the number of even and odd numbers entered from a list; but currently it wont work correctly, think its my modulus operators in the wrong place, but not 100%. Pretty knew to this.
/* Program to count the no of even and odd numbers*/
#include <stdio.h>
void main( )
{
int a[100], n, count_odd=0, count_evn=0,I;
printf("Enter numbers in array");
scanf("%d",&n);
printf("Enter the integars, seperated by a space");
for (I=0;I < n;I++);
scanf("%d",&a[I]);
for(I=0;I < n;I++)
{
if(a[I] % 2 == 0)
count_evn++;
else
count_odd++;
}
printf("There are %d negative numbers in the arrayn\n",count_odd);
printf("There are %d positive numbers in the arrayn",count_evn);
}
Any suggestions would be appreciated. Thanks.
-
Few things first:
Read the sticky posts, you will learn to use code tags.
Read the FAQ, void main should only be used in very few very specific cases, use int main.
As to your code, your problem is probably this line:
for (I=0;I < n;I++);
Get rid of that last semi-colon.
-
That program will not compile, and that is even excluding the fact that void main should be int main.
Furthermore, is this supposed to be C or C++?
Please remember to indent your code properly and post it within [code][/code] bbcode tags.
-
Ah missed that compiler error...