Generation

translateSun, 09 Apr 2023

You are given an integer N and an integer array A as an input. Where N denotes the length of A. Assume that the sum of all elements A to be S. Write a program to return the product of N and S.

#include <iostream> using namespace std; void main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } int sum = 0; for (int i = 0; i < N; i++) { sum = sum + A[i]; } cout << N*sum << endl; }

Questions about programming?Chat with your personal AI assistant