Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ program help

  1. Sep 24, 2007 #1
    What is the program code in c++ to get the sum of given n numbers using pointers?
  2. jcsd
  3. Sep 25, 2007 #2
    "using pointers" is vague, also there is a seperate programming forum...

    if you have a list of length n and some pointer p to the start of that list, of the correct type then:

    Code (Text):

    type sum(type* p, int n)
      type sum = 0;
      for(int i = 0; i < n; i++) sum += p[i];
      return sum;
    is a function that sums the numbers
    Last edited: Sep 25, 2007
  4. Oct 2, 2007 #3
    Thanks for giving an answer to my question.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook