In this, we are going to print the sum of array elements in  C++.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<iostream.h>
void main ()
{
clrscr();
int arr[5] = {1,2,3,4,5}, i, sum = 0;
for (i = 0; i < 5; i++)
{
sum += arr[i];
}
cout << "\nSum of array elements : "<<sum;
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main ()
{
int arr[5] = {1,2,3,4,5}, i, sum = 0;
for (i = 0; i < 5; i++)
{
sum += arr[i];
}
cout << "\nSum of array elements : "<<sum;
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP