/* 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];
clrscr();
cout<<"\n The original array : \n";
for( i = 0; i< 15; i++)
cout<< arr[i] << " ";
cout<<"\n";
rev(arr, 15);
cout<<"\n The reversed array : \n";
for( i = 0; i< 15; i++)
cout<< arr[i] << " ";
getch();
}
/* Whenever you pass an array through function, it will be done only by reference */
#include <iostream.h>
#include <conio.h>
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];
clrscr();
cout<<"\n The original array : \n";
for( i = 0; i< 15; i++)
cout<< arr[i] << " ";
cout<<"\n";
rev(arr, 15);
cout<<"\n The reversed array : \n";
for( i = 0; i< 15; i++)
cout<< arr[i] << " ";
getch();
}
No comments:
Post a Comment