English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a function with two int* arguments begin and end, which give give the boundaries of a memory block of ints, and int argument x, which adds x to every element in the memory block.
The following sample task may help:
Write a function with two int* arguments begin and end, which give the address of the first element in a memory block of integers, and the address of the memory space immediately after the last element in the block, correspondingly, which returns the sum of the elements in the block.

int sum(int* begin, int* end)
{
int* p;
int s;
for (s=0, p=begin; p!=end; ++p)
s+= *p;
return s;

2006-11-29 23:04:07 · 1 answers · asked by christinaf559 1 in Computers & Internet Programming & Design

1 answers

Try this:

void addIt(int* begin, int* end, int x)
{
int* p;
for (p=begin; p!=end; ++p) {
*p = *p + x;
}

2006-11-30 00:13:42 · answer #1 · answered by mchenryeddie 5 · 0 0

fedest.com, questions and answers