Question

Write a C++ function that initializes all the elements of M × N matrix mat to...

Write a C++ function that initializes all the elements of M × N matrix mat to 0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
void calc(int *mat,int M,int N){ //function to initialize elements of M × N matrix mat to 0.
for(int i=0;i<M;i++)
for (int j=0;j<N;j++)
*((mat+i*N)+j)=0;
}
int main() //main function to enter value of M and N
{
int M,N;
cout<<"Enter M and N :";
cin>>M>>N;
int mat[M][N];
calc((int *)mat, M, N);
for(int i=0;i<M;i++){
for (int j=0;j<N;j++)
cout<<mat[i][j]; //prints the value inside Mat
cout<<endl;
}
}

Add a comment
Know the answer?
Add Answer to:
Write a C++ function that initializes all the elements of M × N matrix mat to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT