1aDeclare an array of type integer with 5 elements named iNu

 1)a)Declare an array of type integer with 5 elements named iNumbers. Declare another array named ivalues and initialize it with the values 2, 4, 6, 8, 10 
 b)Declare an array of type float with 3 elements named flValues and initialize it with the values 1.1, 3.3, 5.7 
 C)Write a statement to output the third element of array iValues and first element of array flvalues 
 d)Write a statement to store the value 12 in the last element of array iValues and the value 7 in the element of flValues. 
 e)Declare an integer variable named index.   f)Assign index the correct literal value to access the third element of an array. Using variable index as the subscript output the  third value of the iValues array.      g)Write a while loop using index that will output all the elements of iValues  h)Write a function that takes two arguments. The first is the name of an integer array and the second is the number of elements in the array. The function should display all the elements of the array.      i)Write the prototype for the function above and place it before main(), call the function you wrote and send it the iNumbers array and 5 as the arguments      

Solution


    int iNumbers[5];
int iValues[5]={2,4,6,8,10};

cout<< iValues[2]<<endl;
cout<< flValues[0]<<endl;

iValues[4]=12;
flValues[2]=7;

main.cpp

#include <iostream>
using namespace std;

int fun(int iNumbers[], int num2);

int main( ) {
    int iNumbers[5];
int iValues[5]={2,4,6,8,10};
float flValues[3]={1.1, 3.3, 5.7};
cout<< iValues[2]<<endl;
cout<< flValues[0]<<endl;
iValues[4]=12;
flValues[2]=7;
int index;
index =2;
cout<<iValues[index]<<endl;
index = 0;
while( index < 5 ) {
      cout << iValues[index] << endl;
      index++;
   }
   cout<<endl;
   int ret;
   ret = fun(iNumbers,5);

return 0;

   }

   int fun(int iNumbers[], int num2) {
   int result=0;
   while( result < num2 ) {
      cout << iNumbers[result] << endl;
      result++;
      }
      return 0;
   }

Output :

 1)a)Declare an array of type integer with 5 elements named iNumbers. Declare another array named ivalues and initialize it with the values 2, 4, 6, 8, 10 b)Dec
 1)a)Declare an array of type integer with 5 elements named iNumbers. Declare another array named ivalues and initialize it with the values 2, 4, 6, 8, 10 b)Dec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site