From 336245d38da0ee62d2f16cf303142ae96eb01386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weronika=20Szczegodzi=C5=84ska?= Date: Wed, 30 May 2018 13:56:25 +0000 Subject: [PATCH] Zadanie 1 --- algebra1.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 algebra1.cpp diff --git a/algebra1.cpp b/algebra1.cpp new file mode 100644 index 0000000..3e7ef7b --- /dev/null +++ b/algebra1.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +using namespace std; + +int NWD(int x, int y) +{ + if (y == 0) return x; + else return NWD(y,(x%y)); +} + +void odwracalne(int n) +{ + for(int i = 0; i < n; i++) + { + if(NWD(n,i) == 1) + { + printf("%d ", i); + } + } +} + +void dz_zera(int n) +{ + int pom = 0; + for(int i = 0 ; i < n; i++) + { + pom = 0; + for(int j = 1; j < n; j++) + { + if((i*j) % n == 0) + { + if (pom == 0) + { + printf("%d ", i); + pom++; + } + else continue; + } + } + } +} + +void nilpotentne(int n) +{ + int pom = 0; + for(int i = 0; i < n; i++) + { + pom = 0; + for(int j = 1; j < n; j++) + { + int a = pow(i,j); + if(a % n == 0) + { + if (pom == 0) + { + printf("%d ", i); + pom++; + } + else continue; + } + } + } +} + +void idempotentne(int n) +{ + for(int i = 0; i < n; i++) + { + if((i*i) % n == i) + { + printf("%d ", i); + } + } +} + +int main() +{ + int n; + + printf("Podaj n: "); + scanf("%d", &n); + + printf("\nW Z/%d:\n", n); + printf("Elementy odwracalne: "); + odwracalne(n); + printf("\n"); + + printf("Dzielniki zera: "); + dz_zera(n); + printf("\n"); + + printf("Elementy nilpotentne: "); + nilpotentne(n); + printf("\n"); + + printf("Elementy idempotentne: "); + idempotentne(n); + + return 0; + +}