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();
                }

Just like if you were doing it on paper, you need to remember the numbers that were entered, and then process them after you have all of them.
So you need some kind of a container (such as an array).
Use one loop to enter the data into the container, and other loops to count the odds and evens, and compute the sum.

my only problem is displaying the odd and even numbers, done with the sum part ^_^

i tried looping the array, but to no avail, the numbers in the loop are the numbers that are displayed, will you please tell me what to do exactly on the "Use one loop to enter the data into the container"

1. Use better variable names.
2. Use malloc() to allocate memory for the Number of inputs a. Or a static array.
3. Input All numbers.
4. Loop To check for Odds, display & sum them.
5. Loop To check for Evens, display & sum them.
6. Display sum.
(You can combine steps 4 & 5 by using another array to store Evens/Odds)

i messed up on the arrays, i forgot how to use it, fk

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.