Computer problems,Computer help
*AX SOFT>>>Programming & Design

Help in c++ program?


i want to write a program that calculates arithmatic and geometric mean in c++ , so i need help

You aren't very specific with your request. How will the numbers be input (e.g. entered at the console, constant array, from a file) into the program? Any particular number format (e.g. integers, scientfic notation, simple floating point, double precision, fractions, sequence range, symbolic)?

Do you have a start to your program that you could share? This would help answer some the questions above. Is this a homework problem? Do you simply need hints regarding the general concepts for a computing solution or specific help on how to code certain aspects?

The arithmetic mean is pretty straight forward; it's just the average of your input numbers. However, the geometric mean can be done in several ways. I recommend taking the log of each input number, adding each log (i.e. multiply), dividing (i.e. nth-root) by the number of items, and finally the anti-log. Below is a quick attempt:

#include <math.h>
#include <iostream>
using namespace std;
int main () {
double nums[] ={8.3, 7.5, 1.9, 6.2, 2.4}; // input numbers
int numCount = sizeof(nums); // number of elements
double arithmetic_mean=0.0, geometric_mean=0.0;
for (int counter=0; counter<numCount; counter++) {
arithmetic_mean += nums[counter];
geometric_mean += log(nums[counter]);
}
arithmetic_mean /= numCount; // calc average
geometric_mean = exp(geometric_mean/numCount); // calc e ^ nth-root
cout << "arithmetic mean = " << arithmetic_mean << endl;
cout << "geometric mean = " << geometric_mean << endl;
return 0;
}

Obviously, you'll want to substitute the appropriate input code for the nums[] array. Also, I assumed double precision calculations but you may have different requirements.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Decompile a EXE then recompile it in a seperate exe?

    Yes. But you will only get a version of the source. You would have to rewrite it yourself. In other words, the closest you could get is to see the shell. When the file was converted to machine lan...

  • Can i be come a web designer..or a animator..?

    You can be and do anything you want if you take the time to learn.

    ...
  • What is the name of the top line of a web page browser where there is text?

    It's called the title bar. And since I'm feeling extra amazing today, I'll even tell you how to put it on your own page! :) Not knowing what kind of page you have makes it a l...

  • Help Me Please !!?

    The good news is that anyone in the world can put up a website. The bad news is that there are millions of websites. Search Engine Optimization (SEO ). ...

  • Page breaks?

    Put ur cursor above the break press the left mouse button and drag it to the other part if the break. Release the mouse button and press backspace.. Ur break wil be gone..

    ...
  • How can i make a site like facebook ? can you do it on dreamweaver ?

    You have to learn PHP and mysql.

    ...
  • Whats the code in vb.net to apply a variable in search engine url?

    Don't know Dave ,on your way ...

  • What are the pros and cons of PHP over JSP?

    JSP takes more resources to host the website but is better when you have simultaneous users. I've used PHP for the server-side scripting language for sites that don't get as much traff...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster