My code is correct then why addition is showing something different ?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

My code is correct then why addition is showing something different ?!

Matrix addition

23rd Jun 2021, 4:02 AM
Viraj
Viraj - avatar
3 Answers
+ 2
Guru patel Remove semicolons from for loops. These make loop has void. So, you get junk values.
23rd Jun 2021, 4:19 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 3
#include <iostream> using namespace std; int main() { int arr[10][10],arr1[10][10],arr2[10][10],row,col,i,j; cout<<"enter no of rows for matrix "<<endl; cin>>row; cout<<"enter no of columns for matrix "<<endl; cin>>col; cout<<"enter elements of first"<< row<<" * "<< col<<"matrix"<<endl; for(i=0; i<row ; i++) { for(j=0;j<col;j++) { cin>>arr[i][j]; } //1 st matrix } cout<<"enter elements of second "<<row<<" * "<<col<<"matrix"; for(i=0; i<row ; i++) { for(j=0;j<col;j++) { cin>>arr1[i][j]; } //2 nd matrix } cout<<"output :"; for(i=0;i<row;i++); { for(j=0;j<col;j++); { arr2[i][j]=arr[i][j]+arr1[i][j]; cout<<arr2[i][j]<<" "; } } return 0; } this is the code btw
23rd Jun 2021, 4:02 AM
Viraj
Viraj - avatar
+ 2
Thanks brother
23rd Jun 2021, 4:24 AM
Viraj
Viraj - avatar