Need some help with this program! Thank you in advance! Homework 09A COMSC-044 A
ID: 3695337 • Letter: N
Question
Need some help with this program! Thank you in advance!
Homework 09A COMSC-044 Array Expander Write a function that accepts an int array and the array's size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Take your input data from the file Gradelist.txt. Your program should: Display your n Display the original array; Display the size of the original array; Display the new array that your function generates; Display the size of the new arrayExplanation / Answer
#include<iostream.h>
#include<stdlib.h>
int * arr_exp(int a[], int n)
{
int i,b[100];
for(i=0;i<n*2;i++)
{
if(i<n)
{
b[i]=a[i];
}
else
{
b[i]=0;
}
}
return b;
}
void main()
{
int a[]={1,2,3,4,5,6,7,8,9,20},i;
int *b=arr_exp(a,10);
for(i=0;i<20;i++)
{
cout<<b[i]<<endl;
}
system("pause");
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.