Write a program that has three functions that do the following (identify paramet
ID: 3768786 • Letter: W
Question
Write a program that has three functions that do the following (identify parameters and returned values for each function):
A main() function that calls the other two functions and then displays the norm* (see below).
A fillVector() function to input as many numbers (float) into a list as the user wants. The program should validate input i.e. reject non-numbers.
A computeNorm() function to calculate the norm of the vector. A norm of a vector is defined as the square root of the sum of the squares of vector elements:
* The message displayed by the main() function should be descriptive. For example:
The norm of your vector is 3.74
Write a statement at the bottom of the program to call the main() function.
IT dy 1 For example, givein The norm is lx - vector x = [-23-1] v ( (-29 + 32 + (-1)2 ) = 3.74Explanation / Answer
// a program to find the total of all the elements in array y
#include <iostream>
using namespace std;
// replace every n occurrences with 7
#define n 7
int main()
{
int i, total = 0, y[n] = {6,9,2,4,5,23,12};
for (i=0; i<n; i++)
{
// display the array contents...
cout<<y[i]<<" ";
// do the summing up...
total = total + y[i];
}
// display the result...
cout<<" Sum of 7 numbers in an array is = "<<total<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.