Answer to Question #309337 in C++ for Kyaw

Question #309337

You do not need to use any functions beyond the main function in this problem.

Initialize an array of int with the values: 4, 6, 9, and 12.

Write a for loop to add the values in the array and find their sum.

Use a loop to print the values in the array.

Print the values in the array and the sum in the following format:

4 + 6 + 9 + 12 = 31
  
1
Expert's answer
2022-03-11T14:04:15-0500
#include <iostream>
using namespace std;


int main() {
    const int N=4;
    int arr[N] = {4, 6, 9, 12};
    int sum=0;


    for (int i=0; i<N; i++) {
        sum += arr[i];
    }


    cout << arr[0];
    for (int i=1; i<N; i++) {
        cout << " + " << arr[i];
    }
    cout << " = " << sum << endl;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog