Write a function that has a 2D array as a parameter(ie myfunction(int theArray[]
ID: 675048 • Letter: W
Question
Write a function that has a 2D array as a parameter(ie myfunction(int theArray[][]) ). The function has to ask the user to enter each row of the array as well as store the value. In C language.
example: the array is 3x5
function:
Enter row 0: (user enters) 3 7 5 7 9
Enter row 1: (user enters) 7 6 9 2 1
Enter row 2: (user enters) 4 7 8 3 6
The function will later help a different function count the amount of times a number was entered in the entire array (example: 7 was entered 4 times in the array above).
All help is extremely appreciated! Thanks in advance!!
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void myfunction(int theArray[3][5])
{
int i,j,c=0;
for(i=0;i<3;i++)
{
cout<<"Enter row "<<i+1;
for(j=0;j<5;j++)
{
cin>>theArray[i][j];
}
}
int aa=theArray[0][1];
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
{
if(aa==theArray[i][j])
{
c++;
}
}
}
cout<<"7 was entered "<<c<<" times in the array";
getch();
}
void main()
{
int a[3][5];
myfunction(a);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.