Sunday, July 12, 2009

Write a program In C++ which defines an integer array of size 8.?

Write a program In C++ which defines an integer array of size 8.The array size should be defined by a constant variable.


Read numbers from keyboard for this array.


Interchange the values at position 2 and 7 and then display the array.





Output:


Enter the values for array :


6


5


2


4


8


3


7


12


The values of array after interchange :


6 7 2 4 8 3 5 12

Write a program In C++ which defines an integer array of size 8.?
c++ code:





void main()


{


int arr[8];


cout%26lt;%26lt;"Enter the array values : ";


for(int i=0;i%26lt;=7;i++)


cin%26gt;%26gt;arr[i];





int temp;


temp=arr[1];


arr[1]=arr[6];


arr[6]=temp; //interchanging 2nd and 7th values of array





cout%26lt;%26lt;"\n The array now is: \n"


for(i=0;i%26lt;=7;i++)


cout%26lt;%26lt;" "%26lt;%26lt;arr[i];


}
Reply:For your homework questions, please try to post what you can do yourself so that people can help you, not do your homework for you.


No comments:

Post a Comment