Advertisement
jbonanno

Average arrays

Nov 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. main()
  5. {
  6.    int arrayOne[20], arrayTwo[20], a, b;
  7.  
  8. // The user is asked for the number of elements in the array
  9.    cout << "How many elements are in the array? ";
  10.    cin >> b;
  11.  
  12.    cout << "Please type the elements in array 1" << endl;
  13.  
  14.    for ( a = 0 ; a < b ; a++ )
  15.       cin >> arrayOne[a];
  16.  
  17.    cout << "Please type the elements in array 2 " << endl;
  18.  
  19.    for ( a = 0 ; a < b ; a++ )
  20.       cin >> arrayTwo[a];
  21.  
  22.    cout << "The average of elements of two arrays " << endl;
  23.  
  24.    for ( a = 0 ; a < b ; a++ )
  25.       cout << float(arrayOne[a] + arrayTwo[a])/2 << endl;
  26.  
  27.    return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement