Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int a[20] = {7, 1, 2, 3,};
- void prnt();
- int findMax();
- //////////////////////////////////////////////////
- int main()
- {
- srand(72);
- for(int i = 0; i < 20; i++)
- {
- a[i] = rand()%99;
- }
- prnt();
- int nResult = findMax();
- printf("nResult = %d\n", nResult);
- }
- ///////////////////////////////////////////////////
- int findMax()
- {
- int nMax = a[0],
- nInd = 0 ;
- for(int i = 1; i < 20; i++)
- {
- if(nMax < a[i])
- {
- nMax = a[i];
- nInd = i ;
- }
- }
- return nInd;
- }
- //////////////////////////////////////////////////
- void prnt()
- {
- for(int i = 0; i < 20; i++)
- {
- printf("%2d\n", a[i]);
- }
- }
- /*
- #include <iostream> // vector::back
- #include <vector>
- using namespace std;
- int arr[77];
- int n = 6;
- ////////////////////////////////////////////////////////////
- int main() //
- {
- vector<int> myvector;
- myvector.push_back(10);
- while(myvector.back() != 20)
- {
- myvector.push_back( n++ );
- }
- cout << "myvector contains:";
- for(unsigned i = 0; i < myvector.size(); i ++ )
- {
- cout << ' ' << myvector[i];
- } cout << '\n';
- return 0;
- }
- */
- /*
- // vector::begin/end
- #include <iostream>
- #include <vector>
- int a[77];
- ////////////////////////////////////////////////////////////
- int main () //
- {
- std::vector<int> myvector;
- for(int i=1; i<=5; i++) myvector.push_back(i);
- std::cout << "myvector contains:";
- std::vector<int>::iterator it = myvector.begin();
- while(it != myvector.end() )
- {
- std::cout << ' ' << *it;
- it++;
- }
- std::cout << '\n';
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement