Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that inputs values into a one-dimensional array and finds odd and even Numbers.

Posted on October 16, 2021 By myustaadg.com
Spread the love

Write a program that inputs values into one-dimensional array and finds out the total number of odd and even values entered into one-dimensional array.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Let’s build logic First:

Algorithm for code:

  • Step 1: Start
  • Step 2: Declare an array and variables i, odd and sum.
  • Step 3: Initialized i, odd and even variable equal to zero.
  • Step 4: Take inputs from user.
  • Step 5: Divide array elements one by one with 2 until i < = 9.
  • Step 6: If element divided by 2 is equal to 0 then Even ++.
  • Step 7: If element divided by 2 is not equal to 0 then odd ++.
  • Step 8: Print values
  • Step 9: End program

Code:

Write a program that inputs values into a one-dimensional array and finds out the total number of odd and even values entered into a one-dimensional array.

#include<iostream>
using namespace std;
main()
{
int arr[10], i, odd, even;
i = odd = even = 0;
while(i<=9)
{
cout<<"Enter value into element "<<i<<"?";
cin>>arr[i];
(arr[i]%2==0)? even++ : odd++;
i++;
}
cout<<"\nEven Values : "<<even;
cout<<"\nOdd Values : "<<odd;
}

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well๐Ÿ˜‡ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Array Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/arrays-exercises/

Arrays Exercises, Programming Exercises Tags:Array, Array Example, Array Exercises, Array exercises in C++, Arrays, Arrays in C++, Arrays in Programming, C ++ code to Calculate odd and even in an array, C ++ Program To Count Number Of Even & Odd Elements In Array, C++ How to see if a number in an array is even or odd, C++ Program to Find and Print Odd Numbers in an Array, C++ Program to Find Even and Odd Elements in Array, C++ Program to find even and odd elements in the array, C++ Program to Find Even and Odd Numbers using array, C++ Program to Print Even and Odd Numbers in an Array, C++ program to separate even and odd numbers from an array, Calculate sum of odd and even of an array in C ++, Count even and odd numbers of an array in C++, Count number of even and odd elements in an array?, How do you count and odd number of an array in C++?, How do you determine if an array is even or odd?, How do you find the odd number of an array?, How do you separate an even and odd number in an array?, How do you show even and odd numbers in C++?, How to separate even and odd numbers in an array in C++, Print odd or even numbers using One Dimensional Array in C++, Program to print all the odd numbers in an array, Write a program that inputs values into a one-dimensional array and finds odd and even Numbers., write program to display odd and even numbers

Post navigation

Previous Post: Write a program that initializes the values in the one-dimensional array and computes the sum of even values.
Next Post: Write a program that initializes values 2, 6, 3, 5, 4 and 7 in one-dimensional array and computes the factorial.

More Related Articles

Write a program that asks the user for an integer and shows on the screen whether it is even or odd | Python Programming Programming Exercises
Write a program using two arrays and enter values in 1st array. The program should copy the values of the 1st array to 2nd array. Arrays Exercises
Write a program which input age from user and display on the screen if he/she is of legal age or not | Python Programming Programming Exercises
Write a Program to Build a Simple Calculator in Java Write a Program to Make a Simple Calculator in Java Programming Language | Solved Programming Exercises Programming Exercises
Write a program to enter data into one-dimensional array. Find out the maximum value and its location. Arrays Exercises
Write a program that sorts one-dimensional array of 5 elements in ascending order using insertion sort method. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme