kompilo dhe egzekuto kete kod
Kodi PHP:
#include <iostream>
#include <cstdlib>
double avg(double * score, int size)
{
double total;
for (int i = 0; i < size; ++i)
{
total += score[i];
}
return ( total / (double)size );
}
int main(int argc, char ** argv )
{
double score[10];
if (argc < 2) //no arguments
{
std::cout << "Please enter valid numbers!" << std::endl;
return 0;
}
for (int i = 0; i < argc - 1; ++i) //argc is always at least one so we need to subtract one in case given no parameters.
{
score[i] = atoi(argv[i+1]);
}
std::cout << "The average of the given numbers is: " << avg(score, argc - 1) << std::endl;
return 0;
}