Advertisement
fabbe680

pointers

Jan 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int aSize;
  8.  
  9. cout << "Enter number of elements: ";
  10. cin >> aSize;
  11. cout << endl;
  12.  
  13. //Fill Array
  14.  
  15. int a[aSize];
  16.  
  17. srand(time(NULL));
  18.  
  19. for(int i = 0; i < aSize; i++) {
  20. a[i] = (rand() % (10000 + 1) - 5000);
  21. }
  22.  
  23. //Print Elements
  24.  
  25. for(int i = 0; i < aSize; i++) {
  26. cout << a[i] << endl;
  27. if(i % 200 == 0 && i != 0) {
  28. bool keyPress = false;
  29. while(keyPress == false) {
  30. char key;
  31. cout << endl;
  32. cout << "Continue? [y]" << endl;
  33. cin >> key;
  34. if(key == 'y') {
  35. keyPress = true;
  36. }
  37. }
  38. }
  39. }
  40.  
  41. cout << endl;
  42.  
  43. //Process Array
  44.  
  45. int *p = a, *pMax = p, *pMin = p, tot;
  46.  
  47. for(p; p < (a + aSize); p++) {
  48. tot += *p;
  49. if(*p > *pMax) {
  50. pMax = p;
  51. }
  52. if(*p < *pMin) {
  53. pMin = p;
  54. }
  55. }
  56.  
  57. cout << "Max number is: " << *pMax << endl;
  58. cout << "Min number is: " << *pMin << endl;
  59. cout << "Total is: " << tot << endl;
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement