Final exam, question #2…

Here we are: the final exam. In this video/tutorial, I’m going to explain how to easily write the function for the third question of our final exam. Here is the code and enjoy the ride!

#include <iostream>
#include <vector>
using namespace std;

float prom_numeros(vector<float> nums)
{
float accu=0;
{

for(int i=0; i<nums.size(); i++)
{
accu=accu+nums[i];
} return accu/nums.size();
}
}

int main()
{
vector <float> nums;
nums.push_back(10);
nums.push_back(20);
nums.push_back(30);
nums.push_back(40);
nums.push_back(5);
float prom=prom_numeros(nums);
cout<<prom<<endl;
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s