This code computes the sum and average of the first 5 elements in an array named numbers. The array contains 6 integers: 7, 5, 6, 12, 35, and 27. The code initializes the variables sum and count to 0, and then uses a for loop to iterate through the first 5 elements of the numbers array. Inside the loop, it adds each element to sum and increments count. After the loop, it computes the average by dividing sum by count, and then outputs the sum and average to the console.
#include <iostream> using namespace std; int main() { int numbers[]={7,5,6,12,35,27}; int sum=0; int count=0; int average; cout<<"The numbers are: "; for(int i=0;i<5;i++) { cout<<numbers[i]<<" "; sum+=numbers[i]; ++count; } cout<<"\nSum : "<<sum<<endl; average=sum/count; cout<<"Average : "<<average<<endl; return 0; }To download raw file Click Here
The numbers are: 7 5 6 12 35 Sum : 65 Average : 13
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions