Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


Sum elements in an array
 

 

 

Description

This example shows how to sum all of the elements in an array

Code

/**************************************
sum all of the elments in an array
***************************************/
#include <stdio.h>

void print_arr(int myArray[], int elements);
int sum_arr(int myArray[], int elements);

int main(void)
{
int myArray[5] = {78,34,25,98,12 };
int sum;
printf("Array info: ");
print_arr(myArray,5);
sum = sum_arr(myArray,5);
printf("The sum of the array is : %d\n",sum);
return 0;
}

void print_arr(int myArray[], int elements)
{
int i;
for(i = 0;i < elements;i++)
{
printf("%d ",myArray[i]);
}
printf("\n");
}

int sum_arr(int myArray[], int elements)
{
int i, sum = 0;
for(i = 0;i < elements;i++)
{
sum = sum + myArray[i];
}
return(sum);
}

Information

tested using Visual C++

 

 

 

 

 

Download

arraysum.txt


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Name of Browser(Javascript)
Alert box on page loading(Javascript)
Display all files in a directory(ASP)
keypress example(Darkbasic)
service status(VBScript)
check for a valid date(php)
Search and replace on a string(PHP)
display information about a file(VB)

    




Copyright © 2003 by programmershelp.co.uk