Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #define nstudent 100
- using namespace std;
- int main()
- {
- int student[nstudent];
- int arraySize = sizeof(student) / sizeof(int);
- int total = 0;
- float avg = 0;
- cout << "arraySize: " << arraySize << "\n";
- for(int i=0; i<arraySize; i++)
- {
- srand(time(NULL) + i);
- student[i] = rand() % 11;
- //cout << i << "\n";
- cout << student[i] << "\n";
- }
- for(int i=0; i<arraySize; i++)
- {
- total += student[i];
- }
- cout << "\ntotal: " << total << "\n";
- avg = (float)total / (float)arraySize;
- cout << "\navg: " << avg << "\n";
- //Sort
- for(int i=0; i<arraySize; i++)
- {
- int m = student[i];
- int id = 0;
- for(int j=i+1; j<arraySize; j++)
- {
- if(student[j]>m){m=student[j]; id = j;}
- }
- cout << "iteration " << i << " switching " << student[i] << " for " << student[id] << "\n";
- cout << "student[0]: " << student[0] << "\n";
- student[id] = student[i];
- student[i] = m;
- }
- for(int i=0; i<arraySize; i++)
- {
- cout << i << ". " << student[i] << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement