Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //centralno simetricna u odnosu na sredisnji element
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int length = 5;
- void unos(int matrica[][length]) {
- cout << "Unesite elemente matrice:" << endl;
- for (int i = 0; i < length; i++){
- for (int j = 0; j < length; j++){
- cin >> matrica[i][j];
- }
- }
- }
- void ispis(int matrica[][length]) {
- cout << "Ispis elemenata:" << endl;
- for (int i = 0; i < length; i++){
- for (int j = 0; j < length; j++){
- cout << setw(5) << matrica[i][j];
- }
- cout << endl;
- }
- }
- bool provjeraSimetricnost(int matrica[][length]) {
- for (int i = 0; i < length; i++){
- for (int j = 0; j < length; j++){
- if (matrica[i][j] != matrica[length - 1 - i][length - 1 - j]) {
- return false ;
- }
- }
- }
- return true;
- }
- int main() {
- int matrica[length][length];
- unos(matrica);
- cout << endl;
- ispis(matrica);
- cout << endl;
- if (provjeraSimetricnost (matrica)) {
- cout << "Matrica je centralno simetricna u odnosu na sredisnji element" << endl;
- }
- else {
- cout << "Matrica nije simetricna " << endl;
- }
- system("pause > 0");
- return 0;
- }
- //generisanje Fibonacci
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int length = 5;
- void generisanjeFibonacci(int matrica[][length]) {
- int niz[length*length];
- for (int i = 0; i < length*length; i++)
- {
- if (i == 0) {
- niz[i] = i;
- }
- else if (i == 1) {
- niz[i] = i;
- }
- else {
- niz[i] = niz[i - 2] + niz[i - 1];
- }
- }
- int x = 0;
- for (int i = 0; i < length; i++)
- {
- for (int j = 0; j < length; j++)
- {
- matrica[j][i] = niz[x];
- x++;
- }
- }
- }
- void ispis(int matrica[][length]) {
- for (int i = 0; i < length; i++)
- {
- for (int j = 0; j < length; j++)
- {
- cout << setw(10) << matrica[i][j];
- }
- cout << endl;
- }
- }
- int euklidovAlgoritam(int a, int b) {
- int p, pomocna;
- if (a > b) {
- pomocna = a;
- a = b;
- b = pomocna;
- }
- while (b > 0) {
- p = a;
- a = b;
- b = p % b;
- }
- return a;
- }
- void nzd(int matrica[][length]) {
- int z;
- for (int i = 0; i < length; i++)
- {
- for (int j = 0; j < length; j++)
- {
- cout << "Najveci zajednicki za " << matrica[i][j] << " i " << matrica[length - i - 1][length - j - 1] << " je: ";
- cout << euklidovAlgoritam(matrica[i][j], matrica[length - i - 1][length - j - 1]) << endl;
- }
- }
- }
- int main()
- {
- int matrica[length][length];
- generisanjeFibonacci(matrica);
- ispis(matrica);
- cout << endl;
- nzd(matrica);
- system("pause > 0");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement