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 initializes the values in the one-dimensional array and computes the sum of even values.

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

Write a program that initializes the values in one-dimensional array and computes the sum of even values assigned to the array. It also displays even values and their sum on the screen.

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 variable i, sum.
  • Step 3: Initialized array and sum = 0;
  • Step 4: Divide array element one by one with 2, if reminder is zero then add value in sum.
  • Step 5: Repeat step 4 until i<=9.
  • Step 6: Print sum
  • Step 7: End program

Code:

Write a program that initializes the values in a one-dimensional array and computes the sum of even values assigned to the array. It also displays even values and their sum on the screen.

#include"iostream"
using namespace std;
main()
{
int arr[10]={14,16,34,43,77,34,21,12,33,30};
int i, sum;
i = sum = 0;
while(i<=9)
{
if(arr[i]%2==0)
{
cout<<arr[i]<<endl;
sum = sum + arr[i];
}
i++;
}
cout<<"\nSum of Even Values : "<<sum;
}

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 Exercises, Array exercises in C++, Array sum in C++, Arrays in C++, C++ Program for Sum of Even, C++ Program to Calculate Product and Sum of all Elements, C++ Program to find Sum of Even elements, C++ Program to find Sum of Even inilailize values, C++ Program to find Sum of Even numbers, C++ Program to find Sum of Even values, C++ Program to find the sum of even and odd elements, Calculate sum of odd and even in an array in C++, How can I write a program on C++ to find the sum of the numbers, How can you write a C++ program to print the sum of even numbers using while loop, How do you find the sum of even numbers in c++ programming, How do you find the sum of odd and even numbers?, Program to find sum of elements in a given array, Program to print Sum of even and odd elements in an array, Sum of even elements, Sum of Even numbers in array - c++, Write a program that initializes the values in one-dimensional array and computes the sum of even values assigned to the array. It also displays even values and their sum on the screen., Write a program that initializes the values in the one-dimensional array and computes the sum of even values.

Post navigation

Previous Post: Write a program that assigns values to the individual elements of an array and displays the values of the array.
Next Post: Write a program that inputs values into a one-dimensional array and finds odd and even Numbers.

More Related Articles

Write a program to enter data into one-dimensional array. Find out the maximum value and its location. Arrays Exercises
Write a program that inputs real values into float type array. It reads the value of each element of float type array and assigns to int type array. Arrays Exercises
Write a program that stores the string in a variable, asks the user for the password, and prints on the screen base on condition | Python Programming Programming Exercises
Write a program to initialize values in two tables A and B. Multiply matrix A and B and store results into table C | Multiplication of matrices. Arrays Exercises
Write a program that initializes an array with the number of days of different months. It inputs the number of month and displays the number of days of the entered month. Arrays Exercises
Write a program that inputs ten values in an array and calculates the sum of these values. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme