Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- typedef unsigned int uint;
- using namespace std;
- bool IsNotAnInteger(int n)
- {
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(256, '\n');
- return true;
- }
- if (n < 1) return true;
- return false;
- }
- uint argv(uint arr[], uint n)
- {
- uint sum = 0;
- if (n == 1) return arr[--n]+=2;
- for (uint i = 0; i < n; i++)
- sum += arr[i];
- return sum;
- }
- int main()
- {
- uint n;
- do
- {
- cout << "Unesite koliko brojeva: ";
- cin >> n;
- }
- while (IsNotAnInteger(n));
- uint* arr = new uint[n];
- for (uint i = 0; i < n; i++)
- {
- if (n==1)
- {
- cout << "Unesi broj: ";
- cin >> arr[i];
- }
- else
- {
- cout << "Unesi " << i + 1 << ". broj: ";
- cin >> arr[i];
- }
- }
- cout << argv(arr, n) << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement