Advertisement
rotti321

Suma reale

Dec 13th, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. /*
  2.  
  3. Avem un nr nat n>=1 și un ;ir cu n nr reale.
  4. Cerințe
  5. 1) Afișați suma celor pozitive
  6. 2) Pentru un X dat afisati pozitiile pe care se găsește acesta.
  7.  
  8. Ex:
  9. Date de intrare
  10. 7 3.5
  11. 1 2 3.5 4 -5 6.1 3.5
  12. Date de iesire:
  13. 20.1
  14. 3 7
  15. */
  16. #include <iostream>
  17.  
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22.     int n, poz;
  23.     float a[1000], x, sum=0;
  24.     cin >> n >> x;
  25.     for (int i=1; i<=n; i++) {
  26.         cin >> a[i];
  27.         if (a[i]>0) {
  28.             sum=sum+a[i];
  29.         }
  30.     }
  31.     cout << sum << endl;
  32.     for (int i=1; i<=n; i++) {
  33.         if (a[i]==x) {
  34.             cout << i << " ";
  35.         }
  36.     }
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement