Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int const n = 5;
- int vsota(int a[n][n])
- {
- int leva=0;
- int desna=0;
- int zac=0;
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<n;j++)
- {
- if (i==j)
- {
- leva=leva+a[i][j];
- }
- }
- }
- for (int i=4;i>=0;i--)
- {
- for (int j=4;j>=0;j--)
- {
- if (i==j)
- {
- desna=desna+a[i][j];
- }
- }
- }
- return zac=leva+desna;
- }
- int main()
- {
- srand(time(NULL));
- int a[n][n];
- for (int i=0; i<n;i++)
- {
- for (int j=0;j<n;j++)
- {
- a[i][j]=rand()%50+1;;
- }
- }
- for (int i=0; i<n;i++)
- {
- for (int j=0;j<n;j++)
- {
- cout << a[i][j] << " ";
- }
- cout << "\n";
- }
- cout << "Vsota je: " << vsota(a) << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement