hello guys, i need help, on how to output odd and even numbers at the end of the loop... not the way my program does, which prints the number every time i input numbers, and it needs indicated whether it's an odd or an even number. guys give me an idea on how to do that hehe(algorithm/pseudocode) thank you Daniweb :D
Example on how the program will work
My Code:
Enter number of inputs: 2
Enter number 1: 5
5 - odd
Enter number 2: 69
69 - odd
Sum of even numbers: 0
Sum of odd numbers: 74
How the program should work
Enter number of inputs: 5
Enter number 1: 2
Enter number 2: 7
Enter number 3: 10
Enter number 4: 45
Enter number 5: 30
Even Numbers: 2, 10, 30
Odd Numbers: 7, 45
Sum of even numbers: 42
Sum of odd numbers: 52
#include<stdio.h>
#include<conio.h>
main()
{
int a, b, odd=0, even=0, loop;
printf("\nEnter number of inputs: ");
scanf("%d", &a);
int arrays[a];
for(loop=1; loop<=a; loop++)
{
printf("\nEnter number %d: ", loop);
scanf("%d", &arrays[loop]);
if(loop%2 == 0)
{
even += loop;
printf("\n%d - Even\n", loop);
}
else
{
odd+= loop;
printf("\n%d - Odd\n", loop);
}
}
printf("\nSum of Even Numbers: %d", even);
printf("\nSum of Odd Numbers: %d", odd);
getch();
}