Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

sum of elements in the given array by using function

+1 vote
asked Nov 23, 2018 by anil reddy (130 points)

3 Answers

0 votes
answered Nov 23, 2018 by Юрий Гуреев (1,100 points)

template <typedef T>

T sumElements(const T *array, size_t size)

{

  T sum = T();

  for (size_t i = 0; i < size; ++i) {

    sum += array[i];

  }

  return sum;

}

0 votes
answered Nov 24, 2018 by Nguyen Nguyen Huu Dang (180 points)
program tinhtong;

uses crt;

var

begin

clrscr;

writeln('Nhap so phan tu:');readln(n);

for i:=1 to n do

begin

  write('Nhap phan tu thu ',i);readln(a[i]);

end;

s:=0;

 for i:=1 to n do

 begin

  s:=s+ a[i];

i:=i+1;

end;

writeln('Tong la:',s);

readln;

end.

//mình chưa test lại nên sai thì bạn bỏ qua mình lớp 7
0 votes
answered Nov 24, 2018 by Nguyen Nguyen Huu Dang (180 points)
Bạn chuyển về tiếng anh là cái chương trình nha
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...