Search
 
SCRIPT & CODE EXAMPLE
 

CPP

average of a matrix c++

#include <iostream>
using namespace std;

int main()
{
    int n, i;
    float num[100], sum=0.0, average;

    cout << "Enter the numbers of data: ";
    cin >> n;

    while (n > 100 || n <= 0)
    {
        cout << "Error! number should in range of (1 to 100)." << endl;
        cout << "Enter the number again: ";
        cin >> n;
    }

    for(i = 0; i < n; ++i)
    {
        cout << i + 1 << ". Enter number: ";
        cin >> num[i];
        sum += num[i];
    }

    average = sum / n;
    cout << "Average = " << average;

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: did greeks write c++ codes? 
Cpp :: climits in cpp 
Cpp :: compile notepad++ c++ 
Cpp :: void value not ignored as it ought to be 
Cpp :: c++ nodiscard 
Cpp :: c++ find index of an element 
Cpp :: c++ run loop for 5 seconds 
Cpp :: c++ random number generator 
Cpp :: print queue c++ 
Cpp :: c++ std::find with lambda 
Cpp :: remove value from vector c++ 
Cpp :: finding no of unique characters in a string c++ 
Cpp :: how to hide ui elements unity 
Cpp :: cpp rand 
Cpp :: c++ check if file exits 
Cpp :: Sort array using inbuilt sort function in decreasing order 
Cpp :: fork was not declared in this scope 
Cpp :: string to integer convert c++ 
Cpp :: how to get a letter from the user c++ string 
Cpp :: optimized bubble sort 
Cpp :: include spaces while reading strings in cpp 
Cpp :: how to round a double to 2 decimal places in c++ 
Cpp :: C++ do...while Loop 
Cpp :: how to round to nearest whole number unity 
Cpp :: print vector of vector c++ 
Cpp :: what is the associative property of an operator 
Cpp :: cpp binary tree 
Cpp :: segmented sieve of Eratosthenes in cpp 
Cpp :: c++ first letter of string 
Cpp :: the code execution cannot proceed because glew32.dll was not found 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =