#include
void main( )
{
int x,count,countEven,countOdd,num;
printf("Enter number of data\n");
scanf("%d",&count);
while(x
printf("Enter positive interger:\n");
scanf("%d",&num);
if(num%2==0)
countEven++;
else
x++;
}
countOdd++;
printf("Number of even intergers is %d\n",countEven);
printf("Number of odd intergers is %d\n",countOdd);
}
//countOdd represents the number of odd intergers
//countEven represents the number of even intergers
//count represents the amount of data to be input
//x represents number of digits entered
PLEASE HELP ME FIND WHERE THIS CODE IS GOING WRONG
Neha SharmaPosted Oct 25, 2012, 8:53 AM
Kunal VaishyaPosted Oct 25, 2012, 8:52 AM
x = 1;
count = 0;
countEven = 0;
countOdd = 0;
Sivaraman DhamodaranPosted Oct 25, 2012, 8:49 AM
1) Before entering the while loop,
put x = count;
2) In the else, increment the odd number count
3) After the conditional check, reduce the value in x by one
scanf("%d",&count);
x = count;
countEven = 0;
countOdd = 0;
while(x
{
printf("Enter positive interger:\n");
scanf("%d",&num);
if(num%2==0)
countEven++;
else
{
//x++;
countOdd++;
}
x--;
}
Modified: Thanks Kunal. Forgot to Init other variables :)