C++ Online Compiler
Example: Plus Minus in C++ Program
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Plus Minus in C++ Program #include <iostream> #include <iomanip> using namespace std; int main() { int s=0; cout << "Enter the size of the array::\n"; cin >> s; float arr[s]; cout << "Enter the " << s << " elements of the array::\n"; // It will read the inputs of the array's elements + calculate the plus-minus values int i=0; float r1=0,r2=0,r3=0; while (i<s) { cin >> arr[i]; if (arr[i] > 0) r1++; if (arr[i] < 0) r2++; if (arr[i] == 0) r3++; i++; } r1 = r1/s; r2 = r2/s; r3 = r3/s; // It will print the final output cout << fixed << setprecision(6) << "\n\n" << r1 << endl << r2 << endl << r3 << endl; return 0; }
8 4 1 -4 -5 3 -9 0 -9
Output
Clear
ADVERTISEMENTS