Array:
Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.
Example-
Array is {3,2,4,1,5}
After square the array, {9,4,16,1,25}
program:
#include < iostream>
using namespace std;
class r4r
{
public:
//class method or function
int square(int *a,int n)
{
int i;
cout<<"Array after square each element"<< endl;
for(i=0;i< n;i++)
{
cout<< a[i]*a[i]<<" ";
}
}
};
int main()
{
int a[100],i,n;
r4r obj;
cout<<"Enter number of element in array?"<< endl;
cin>>n;
cout<<"Enter number in array"<< endl;
for(i=0;i< n;i++){
cin>>a[i];
}
//pass in function
obj.square(a,n);
return 0;
}
Enter number of element in array
5
Enter number in array
1 2 3 4 5
Array after square each element
1 4 9 16 25