Arrays Tasks
Arrays Tasks
ARRAY INPUT
--------------------------------------------------
int n;
cout<<"Enter number of array elements: ";
cin>>n;
int array[n];
--------------------------------------------------------
ADDING TWO ARRAYS
--------------------------------------------------------
#include <iostream>
using namespace std;
int main() {
// Define two arrays
int a[2] = {0, 1};
int b[2] = {2, 3};
int c[2]; // Resultant array
return 0;
}
--------------------------------------------------------
#include <iostream>
using namespace std;
int main() {
int n;
return 0;
}
------------------------------------------------------
AVERAGE MARKS USING ARRAY
------------------------------------------------------
#include <iostream>
using namespace std;
int main() {
int students = 5;
float marks[students];
float sum = 0;
cout << "Enter the marks of " << students << " students: ";
for (int i = 0; i < students; i++) {
cin >> marks[i]; // input marks
sum += marks[i]; // add marks to sum
}
cout << "The average marks of the students are: " << average << endl;
return 0;
}
-------------------------------------------------------------
AVERAGE MARKS
-------------------------------------------------------------
#include <iostream>
using namespace std;
int main() {
int score = 5;
float marks[score];
float sum = 0;
cout << "Enter the marks of " << score << " students: ";
for (int i = 0; i < score; i++) {
cin >> marks[i]; // input marks
sum += marks[i]; // add marks to sum
}
cout << "The average marks of the students are: " << average << endl;
return 0;
}