Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

C++ Programming/Exercises/Static arrays

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

include <iostream> using namespace std; void enterNumbers(int arr[], int n) { cout << "Enter " << n << " numbers:\n"; for (int i = 0; i < n; ++i) cin >> arr[i]; } void countAndTotal(int arr[], int n, int& pos, int& neg, int& total) { pos = neg = total = 0; for (int i = 0; i < n; ++i) { if (arr[i] > 0) pos++; else if (arr[i] < 0) neg++; total += arr[i]; } } int main() { int n, arr[100], pos, neg, total; cout << "Enter the number of elements: "; cin >> n; enterNumbers(arr, n); countAndTotal(arr, n, pos, neg, total); cout << "Positives: " << pos << "\nNegatives: " << neg << "\nTotal: " << total << endl; return 0; }