Add number to array in C++ by R4R Team

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.

What we do here?
Example-
Array is {1,2,3,4,5}
Add 2 in Array then {3,4,5,6,7}

program:

#include < iostream>
using namespace std;
class r4r
{
public:
//class method or function
int function(int *arr,int n)
{
int i;
cout<<"Array after number add is:"<< endl;
for(i=0;i< 5;i++)
{
cout<< arr[i]+n<<" ";
}
}
};
int main()
{
int a[5],i,n;
r4r obj;
cout<<"Enter 5 number in array"<< endl;
for(i=0;i< 5;i++){
cin>>a[i];
}
cout<<"Enter number to add in array"<< endl;
cin>>n;
//pass in function
obj.function(a,n);
return 0;
}


output-

Enter 5 number in array
1 2 3 4 5
Enter number to add in array
2
Array after number add is:
3 4 5 6 7




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!