Advertisement
Razija

sabiranjeMatrica

Oct 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main(){
  5.  
  6. int x[10][10], y[10][10], z[10][10];
  7. int i, j, M, N;
  8.  
  9. cout<<"Unijeti dimezije matrice X koje su ujedno i dimenzije matrice Y: "<<endl;
  10. do{
  11. cout<<"broj redova: "; cin>>N;
  12. cout<<"broj kolona: "; cin>>M;
  13. } while((N>10)||(M>10));
  14. cout<<endl;
  15.  
  16.  
  17.  
  18. cout<<"unestite elemente X matrice: "<<endl;
  19. for(int i=0; i<N; i++){
  20. cout<<endl<<"unesite elemente niza: "<<endl;
  21. for(int j=0; j<M; j++){
  22. cout<<"x["<<i<<"]["<<j<<"]= ";
  23. cin>>x[i][j];
  24. }
  25. }
  26. cout<<endl;
  27.  
  28. cout<<"unestite elemente Y matrice: "<<endl;
  29. for(int i=0; i<N; i++){
  30. cout<<endl<<"unesite elemente niza: "<<endl;
  31. for(int j=0; j<M; j++){
  32. cout<<"y["<<i<<"]["<<j<<"]= ";
  33. cin>>y[i][j];
  34. }
  35. }
  36. cout<<endl;
  37.  
  38. //ispis matrica X i Y
  39. cout<<"Matrica X: "<<endl;
  40. for(int i=0; i<N; i++){
  41. for(int j=0; j<M; j++){
  42. cout<<setw(5)<<x[i][j];
  43. } cout<<endl;
  44. }
  45. cout<<endl;
  46.  
  47. cout<<"unijeli ste matricu Y: "<<endl;
  48. for(int i=0; i<N; i++){
  49. for(int j=0; j<M; j++){
  50. cout<<setw(5)<<y[i][j];
  51. } cout<<endl;
  52. }
  53. cout<<endl;
  54.  
  55. //X+Y
  56. cout<<"zbir matrica X i Y je:"<<endl;
  57. for(int i=0; i<N; i++){
  58. for(int j=0; j<M; j++){
  59. cout<<setw(5)<<x[i][j]+y[i][j];
  60. }cout<<endl;
  61. }
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement