64 679
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #73318 in C++ for Sani

Question #73318
Initialize an integer array of size 10; pass it to a function ‘arrIncrement’ using a pointer. The function should increment all elements of the array by one. Then display the updated array on screen.Give me code of this in c++
Expert's answer
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
void arrGenerate(int *a, int size)
{
srand(time(0));
for (int i = 0; i < size; i++)
a[i] = rand() % 100;
}
void arrPrint(int *a, int size)
{
for(int i=0; i<size; i++)
{
cout<<a[i]<<' ';
}
cout<<endl;
}
void arrIncrement(int *a, int size)
{
for(int i=0; i<size; i++)
{
a[i]++;
}
}
int main(int argc, char** argv)
{
const int N=10;
int arr[N];
arrGenerate(arr, N);
arrPrint(arr, N);
arrIncrement(arr, N);
arrPrint(arr, N);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions