Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*Fare un programma in C++ che restituisca la somma di due array
  6. di 10 numeri con la virgola ovvero che sommi le componenti con lo
  7. stesso indice in un nuovo array. Quindi calcolare la media dei numeri
  8. di questo array risultante e stampi il totale degli eventuali numeri
  9. negativi presenti nell’array.*/
  10.  
  11. int main (){
  12.  
  13. float array[10], array1[10], somma = 0, neg = 0;
  14. int j = 0;
  15. for (int i = 0; i < 20; i++){
  16. if(i < 10) {
  17. cout << "Inserisci il " << i + 1 << " numero del primo array: ";
  18. cin >> array[i];
  19. if ( array[i] < 0 ){
  20. neg += array[i];
  21. }
  22. somma += array [i];
  23. }
  24. else {
  25. cout << "Inserisci il " << j + 1 << " numero del secondo array: ";
  26. cin >> array1[j];
  27. if ( array1[j] < 0){
  28. neg += array1[j];
  29. }
  30. somma += array [j];
  31. j++;
  32. }
  33. }
  34. cout << "\n\nLa somma dei numeri positivi e' " << somma << ", la media e' " << somma / 20 << " e la somma dei numeri negativi e' " << neg;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement