Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ average

// Average of a float

float avg(float numbers[]) {
  
	int arraylength = sizeof(arr)/sizeof(arr[0]);
	float sum = 0;
  	
  	for (int i = 0; i < arraylength; i++) {
    	sum += numbers[i];
    }
  
  	return sum / arraylength;
} 
Comment

C++ Compute Average

    int a, b, c, d, sum, average;

    cout << "Input the 1st number: ";
    cin >> a;
    cout << "Input the 2nd number: ";
    cin >> b;
    cout << "Input the 3rd number: ";
    cin >> c;
    cout << "Input the 4th number: ";
    cin >> d;

    sum = a+b+c+d;
    average = sum/4;

    cout << "The average is: " << average << endl;
Comment

PREVIOUS NEXT
Code Example
:: how to search in array c++ 
Cpp :: hello world in c/++ 
Cpp :: conditional operator in c++ 
Cpp :: union of two arrays leetcode 
Cpp :: print duplicate characters from string in c++ 
Cpp :: how to get the time in c++ as string 
Cpp :: find kth max and min element in an array 
Cpp :: image shapes in opencv c++ 
Cpp :: c++ get the line which call a function 
Cpp :: argument vs parameter coding c++ 
Cpp :: odd numbers 1 to 100 
Cpp :: C++ float and double Different Precisions For Different Variables 
Cpp :: priority queue in c++ 
Cpp :: how to make Dijkstra in c++ 
Cpp :: sort c++ 
Cpp :: C++ New Lines 
Cpp :: set to vector 
Cpp :: joining two vectors in c++ 
Cpp :: print hello world c++ 
Cpp :: resize string c++ 
Cpp :: Subarray with given sum in c++ 
Cpp :: unpack tuple c++ 
Cpp :: c++ for each loop 
Cpp :: stack class implementation to file unix-style in c++ 
Cpp :: Exit Button c++ code 
Cpp :: loop execution descending order in c++ 
Cpp :: how to declare a 2d vector stack 
Cpp :: Operators in C / C++ 
Cpp :: cout stack in c++ 
Cpp :: assign one vector to another c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =