Thread: sum of n numbers using arrays

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    6

    sum of n numbers using arrays

    Hello sir,
    I need a simple program.
    sum of n numbers using arrays in C

  2. #2
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Although I'm rather new to C, this is one method:

    Code:
    int add_array()
    {
    	int array_step = 0;
    	int result = 0;
    	
    	for(array_step = 0, array_step < array_limit, array_step++)
    	{
    		result += your_array[array_step];
    	}
    	
    	return(result);
    }
    If you defined your array as "int your_array[80];" the "array_limit" value is this 80 value.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    6

    Error

    I cant follow your code sir.
    I need full coding for sum of n numbers using arrays

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    If you need it - you should write it.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Make an effort, don't just dump your homework and expect a free handout.
    http://cboard.cprogramming.com/annou...t.php?f=4&a=39

    Feel free to start a new thread with an attempt at solving it yourself. At least make it look like you did more than just walk from your class to the nearest web browser to post your assignment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sum of 2 int arrays
    By maro009 in forum C++ Programming
    Replies: 6
    Last Post: 10-21-2005, 02:07 PM
  2. Replies: 4
    Last Post: 04-19-2005, 08:05 PM
  3. comparing arrays
    By dustyrain84 in forum C Programming
    Replies: 1
    Last Post: 01-21-2004, 05:52 PM
  4. Finding and Printing prime numbers using arrays
    By Sektor in forum C++ Programming
    Replies: 5
    Last Post: 12-11-2003, 08:29 PM
  5. Array's Help
    By bmx4christ in forum C Programming
    Replies: 15
    Last Post: 12-08-2003, 12:40 PM