C++ iki boyutlu dizi toplamı, çıktı yanlış

Lorin1987

Üye
Katılım
8 Tem 2021
Mesajlar
23
Puanları
1
Yaş
37
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];
}
}
 
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?
 
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:
Teşekkürler
 

Forum istatistikleri

Konular
127,952
Mesajlar
913,881
Kullanıcılar
449,600
Son üye
psychedelic

Yeni konular

Geri
Üst