"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Saturday, February 20, 2010

Write a complete C++ program that reads a float array having 15 elements. The Program uses a function reverse() to reverse this array. Make suitable assumption.

/* This example is also demonstrating function with call by reference  */
/* Whenever you pass an array through function, it will be done only by reference */


void rev(float a[ ], int n)
float t;
for(int i =0, k = n-1; i< n/2 ; i++, k--)
t = a[i];
a[i] = a[k];
a[k] = t;

void main()
float arr[15];

cout<< "\n Enter 15 real numbers :";
for(int i = 0; i< 15 ; i++)
cin>> arr[i];

cout<<"\n The original array : \n";
for( i = 0; i< 15; i++)
cout<< arr[i] << "  ";


rev(arr, 15);

cout<<"\n The reversed array : \n";

for( i = 0; i< 15; i++)
 cout<< arr[i] << " ";


No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.