Posted by : Unknown
Wednesday, 24 December 2014
This is a sample code to calculate average using array and for loop... for understanding array and for loop you may consult our explanation on that.
#include<iostream>
#include<conio.h>
using namespace std;
void main() {
int arr[10] = { 0 };
int result = 0;
for (int i = 0; i < 10; i++){
cin >> arr[i];
}
for (int i = 0; i < 10; i++){
result += arr[i];
}
result /= 10;
cout << "The average is: " << result;
}
#include<iostream>
#include<conio.h>
using namespace std;
void main() {
int arr[10] = { 0 };
int result = 0;
for (int i = 0; i < 10; i++){
cin >> arr[i];
}
for (int i = 0; i < 10; i++){
result += arr[i];
}
result /= 10;
cout << "The average is: " << result;
}