SergeyNasekin

Pointers Exercise 3

May 25th, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. \\ Array
  2. #include<iostream>
  3. int main(){
  4.     int size = 0, max = -2147483648;
  5.     int *pSize = &size, *pMax = &max;
  6.     std::cout << "Enter how much values do you want: " << std::endl;
  7.     std::cin >> *pSize;
  8.     int array [size];
  9.     for(int i = 0; i < *(pSize); ++i){
  10.         std::cout << "Enter " << i+1 << " number: ";
  11.         std::cin >> *(&array[0]+i);
  12.         std::cout << std::endl;
  13.         if (*(&array[0]+i) > max)
  14.             *pMax = *(&array[0]+i);
  15.     }
  16.     std::cout << " Your max value = " << *pMax;
  17. }
  18.  
  19. \\one int
  20. #include<iostream>
  21. int main(){
  22.     int size = 0, max = -2147483648, value = 0;
  23.     int *ptrSize = &size, *ptrMax = &max, *ptrValue = &value;
  24.     std::cout << "Enter how much values do you want: " << std::endl;
  25.     std::cin >> *ptrSize;
  26.     for(int i = 0; i < *(ptrSize); ++i){
  27.         std::cout << "Enter " << i+1 << " number: ";
  28.         std::cin >> *ptrValue;
  29.         std::cout << std::endl;
  30.         if ( *ptrValue > max)
  31.             *ptrMax = *ptrValue;
  32.     }
  33.     std::cout << " Your max value = " << *ptrMax;
  34. }
Add Comment
Please, Sign In to add comment