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++
1
Expert's answer
2018-02-09T06:18:59-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS