Lorin1987 Üye Katılım 8 Tem 2021 Mesajlar 23 Puanları 1 Yaş 37 19 Ağu 2021 #1 Kod: #include using namespace std; int main() {int sum(int a[5][5],int b[5][5]); int i,j,g[5][5],h[5][5],d[5][5]; for(i=0;i {for(j=0;j { cin>>g[i][j]; } } cout< for(i=0;i { for(j=0;j { cin>>h[i][j]; } } cout<<"Matrix sum"<<endl; d[i][j]=sum(g,h); for(i=0;i<5;i++) {for(j=0;j<5;j++) {cout<<d[i][j]<<" "; } cout<<endl; } return 0; } int sum(int a[5][5],int b[5][5]) { int c[5][5],i,j; for(i=0;i<5;i++) {for(j=0;j<5;j++) { c[i][j]=a[i][j]+b[i][j]; } }
Kod: #include using namespace std; int main() {int sum(int a[5][5],int b[5][5]); int i,j,g[5][5],h[5][5],d[5][5]; for(i=0;i {for(j=0;j { cin>>g[i][j]; } } cout< for(i=0;i { for(j=0;j { cin>>h[i][j]; } } cout<<"Matrix sum"<<endl; d[i][j]=sum(g,h); for(i=0;i<5;i++) {for(j=0;j<5;j++) {cout<<d[i][j]<<" "; } cout<<endl; } return 0; } int sum(int a[5][5],int b[5][5]) { int c[5][5],i,j; for(i=0;i<5;i++) {for(j=0;j<5;j++) { c[i][j]=a[i][j]+b[i][j]; } }
tr_escape Üye Katılım 6 May 2008 Mesajlar 634 Puanları 16 19 Ağu 2021 #2 Sanırım copy paste yaparken bir çok parantez vs uçmuş... For döngülerinin sonu belirsiz. Düzenleyebilir misiniz ya da bir kaynak varsa onu gösterebilir misiniz?
Sanırım copy paste yaparken bir çok parantez vs uçmuş... For döngülerinin sonu belirsiz. Düzenleyebilir misiniz ya da bir kaynak varsa onu gösterebilir misiniz?
FakirMaker Usta Üye Katılım 5 May 2009 Mesajlar 1,129 Puanları 181 19 Ağu 2021 #3 C++: #include <iostream> using namespace std; int main() { int r, c, a[100][100], b[100][100], sum[100][100], i, j; cout << "Enter number of rows (between 1 and 100): "; cin >> r; cout << "Enter number of columns (between 1 and 100): "; cin >> c; cout << endl << "Enter elements of 1st matrix: " << endl; // Storing elements of first matrix entered by user. for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << "Enter element a" << i + 1 << j + 1 << " : "; cin >> a[j]; } // Storing elements of second matrix entered by user. cout << endl << "Enter elements of 2nd matrix: " << endl; for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << "Enter element b" << i + 1 << j + 1 << " : "; cin >> b[j]; } // Adding Two matrices for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) sum[j] = a[j] + b[j]; // Displaying the resultant sum matrix. cout << endl << "Sum of two matrix is: " << endl; for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << sum[j] << " "; if(j == c - 1) cout << endl; } return 0; } Son düzenleme: 19 Ağu 2021
C++: #include <iostream> using namespace std; int main() { int r, c, a[100][100], b[100][100], sum[100][100], i, j; cout << "Enter number of rows (between 1 and 100): "; cin >> r; cout << "Enter number of columns (between 1 and 100): "; cin >> c; cout << endl << "Enter elements of 1st matrix: " << endl; // Storing elements of first matrix entered by user. for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << "Enter element a" << i + 1 << j + 1 << " : "; cin >> a[j]; } // Storing elements of second matrix entered by user. cout << endl << "Enter elements of 2nd matrix: " << endl; for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << "Enter element b" << i + 1 << j + 1 << " : "; cin >> b[j]; } // Adding Two matrices for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) sum[j] = a[j] + b[j]; // Displaying the resultant sum matrix. cout << endl << "Sum of two matrix is: " << endl; for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << sum[j] << " "; if(j == c - 1) cout << endl; } return 0; }