Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zadanie2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] tab1 = { 1, 3, 5, 7, 9 };
- int[] tab2 = { 1, 1, 1, 0, 1, 0, 0, 0 };
- int[,] tab2D = new int[10, 10];
- Console.WriteLine("1.1) " + getArithAverage(tab1));
- Console.Write("1.2) "); makeMirrorTable(tab1);
- wyswietlTablice(tab1);
- Console.Write("1.3) "); exchangeMinMax(tab1);
- Console.Write("1.4) "); insertZeros(tab1);
- wyswietlTablice(tab1);
- Console.WriteLine("1.5) "); doExORTable(tab2);
- Console.WriteLine("1.6) "); makeIdentity(tab2D);
- Console.WriteLine("1.7) "); makeMatrixProduct(tab2D);
- Console.WriteLine(/*1.8)*/getRowColSum(tab2D,9,9));//wartosci 1-9
- Console.ReadKey();
- string tekst = "przykladowy tekst";
- string imie = "Krzysztof";
- string zdanie = "PrzyklAdoweZdanie";
- string zdanie2 = "Nazywam sie Przywara";
- string liczba = "12345";
- char znak = 'e';
- Console.WriteLine("2.1) {0}", getCharIndex(tekst, znak));
- Console.WriteLine("2.2) {0}", getWordsNumber(tekst));
- Console.WriteLine("2.3) {0}", isMale(imie));
- Console.WriteLine("2.4) {0}", insertSpaces(zdanie));
- Console.WriteLine("2.5) {0}", insertWord(zdanie2, imie, 2));
- Console.WriteLine("2.6) {0}", toLower(zdanie));
- Console.WriteLine("2.7) {0}", convertFromStringToNumber(liczba));
- Console.WriteLine("2.8) {0}", caeserCipher(tekst));
- Console.ReadKey();
- Console.WriteLine("3.1) {0}", makeLogicSum(true, false));
- Console.WriteLine("3.2) {0}", getRootsNumber(1, 8, 12));
- Console.WriteLine("3.3) {0}", factorial(3));
- Console.WriteLine("3.4) {0}", absoluteValue(-30));
- Console.WriteLine("3.5) {0}", getIntegerFromReal((float)12.345));
- Console.WriteLine("3.6) {0}", getDecimalDigits(12345670));
- Console.WriteLine("3.7) {0}", inverseNumber(8));
- Console.WriteLine("3.8) {0}", reverseNumber(159));
- Console.ReadKey();
- }
- static void wyswietlTablice(int[] tab)
- {
- for (int i = 0; i < tab.Length; i++)
- {
- Console.Write(tab[i]+", ");
- }
- Console.WriteLine();
- }
- static float getArithAverage(int[] table)
- {
- int suma = 0;
- float avarage;
- for(int i=0; i < table.Length;i++)
- {
- suma += table[i];
- }
- avarage = suma / table.Length;
- return avarage;
- }
- static void makeMirrorTable(int[] table)
- {
- int tmp;
- for (int i = 0; i < table.Length; i++)
- {
- tmp = table[i];
- table[i] = table[table.Length - 1-i];
- table[table.Length - 1 - i] = tmp;
- }
- }
- static void exchangeMinMax(int[] table)
- {
- int min = table[0];
- int max = table[0];
- for (int i=0; i < table.Length; i++)
- {
- if (min > table[i])
- {
- min = table[i];
- }
- if (max < table[i])
- {
- max = table[i];
- }
- }
- Console.WriteLine("Minimalna: " + min + ", Maksymalna: " + max);
- }
- static void insertZeros(int[] table)
- {
- int dziel;
- for (int i = 0; i < table.Length; i++)
- {
- dziel = table[i] % 3;
- if (dziel == 0)
- {
- table[i] = 0;
- }
- }
- }
- static void doExORTable(int[] binaryTable)
- {
- int sum,xor;
- for (int i = 0; i < (binaryTable.Length - 1); i++)
- {
- sum = binaryTable[i]+binaryTable[i+1];
- xor = sum % 2;
- Console.WriteLine("Xor " + (i + 1) + "-ego elementu tablicy i " + (i + 2)+"-ego: "+xor);
- }
- // ostatni i pierwszy element
- sum = binaryTable[0] + binaryTable[binaryTable.Length-1];
- xor = sum % 2;
- Console.WriteLine("Xor 1-ego elementu tablicy i " + (binaryTable.Length) + "-ego: " + xor);
- }
- static void makeIdentity(int[,] tab2D)
- {
- for(int i = 0; i < tab2D.GetLength(0);i++)
- {
- for(int j = 0; j < tab2D.GetLength(1); j++)
- {
- if (i == j)
- {
- tab2D[i, j] = 1;
- }
- Console.Write(tab2D[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static void makeMatrixProduct(int[,] tab2D)
- {
- for (int i = 0; i < tab2D.GetLength(0); i++)
- {
- tab2D[i, 0] = (i + 1);
- for (int j = 0; j < tab2D.GetLength(1); j++)
- {
- tab2D[0, j] = (j + 1);
- //Console.Write(tab2D[i, j] + " ");
- }
- //Console.WriteLine();
- }
- for (int i = 1; i < tab2D.GetLength(0); i++)
- {
- for (int j = 1; j < tab2D.GetLength(1); j++)
- {
- tab2D[i, j] = i * j;
- Console.Write( "{0:D2} ",tab2D[i, j]);
- }
- Console.WriteLine();
- }
- }
- static int getRowColSum(int[,] tab2D, int row, int col)
- {
- int sum = 0;
- for (int i = 1; i < tab2D.GetLength(0); i++)
- {
- sum += tab2D[i, col];
- // Console.WriteLine(sum);
- }
- for (int j = 1; j < tab2D.GetLength(1); j++)
- {
- sum += tab2D[row, j];
- // Console.WriteLine(sum);
- }
- Console.Write("1.8) Suma " + col + "-ej kolumny i " + row + "-ego wiersza to: ");
- return sum;
- }
- static int getCharIndex(string text, char mark)
- {
- for (int i = 0; i < text.Length; i++)
- {
- if (mark == text[i])
- {
- return i;
- }
- }
- return -1;
- }
- static int getWordsNumber(string text)
- {
- int licz = 1;
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == ' ')
- {
- licz++;
- }
- }
- return licz;
- }
- static bool isMale(string text)
- {
- if (text[text.Length - 1] == 'a')
- {
- return false;
- }
- else return true;
- }
- static string insertSpaces(string text)
- {
- string newText = "";
- newText += text[0];
- for (int i = 1; i < text.Length; i++)
- {
- if ((int)text[i] < 91)
- {
- newText += " " + text[i];
- }
- else newText += text[i];
- }
- return newText;
- }
- static string insertWord(string text, string word, int spaceIndex)
- {
- int licz = 0;
- string newText = "";
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == ' ')
- {
- licz++;
- }
- if (licz == spaceIndex)
- {
- newText += " " + word;
- licz = 9999;
- }
- newText += text[i];
- }
- return newText;
- }
- static string toLower(string text)
- {
- string newText = "";
- for (int i = 0; i < text.Length; i++)
- {
- if ((int)text[i] < 91)
- {
- newText += (char)((int)text[i] + 32);
- }
- else newText += text[i];
- }
- return newText;
- }
- static int convertFromStringToNumber(string number)
- {
- int liczba = Convert.ToInt32(number);
- return liczba;
- }
- static string caeserCipher(string text)
- {
- string newText = "";
- for (int i = 0; i < text.Length; i++)
- {
- if (text[0] != ' ')
- {
- if (((int)text[i] > 64 && (int)text[i] < 91) || ((int)text[i] > 96 && (int)text[i] < 123))
- {
- if (((int)text[i] > 64 && (int)text[i] < 88) || ((int)text[i] > 96 && (int)text[i] < 120))
- {
- newText += (char)((int)text[i] + 3);
- }
- else
- {
- newText += (char)((int)text[i] - 23);
- }
- }
- else
- {
- newText += text[i];
- }
- }
- }
- return newText;
- }
- static bool makeLogicSum(bool val1, bool val2)
- {
- if (val1 == false && val2 == false)
- return false;
- else
- return true;
- }
- static int getRootsNumber(float a, float b, float c)
- {
- float delta = b * b - 4 * a * c;
- if (delta > 0)
- return 2;
- else if (delta == 0)
- return 1;
- else return 0;
- }
- static long factorial(int n)
- {
- if (n < 1)
- return 1;
- else
- return n * factorial(n - 1);
- }
- static float absoluteValue (float number)
- {
- if (number < 0)
- {
- return number * (-1);
- }
- else
- return number;
- }
- static int getIntegerFromReal(float number)
- {
- return (int)number;
- }
- static int getDecimalDigits(int number)
- {
- int licz = 0;
- while (number > 0)
- {
- licz++;
- number = number / 10;
- }
- return licz;
- }
- static double inverseNumber(double number)
- {
- if (number == 0)
- {
- Console.WriteLine("Dzielenie przez zero");
- return 0;
- }
- else
- {
- return 1 / number;
- }
- }
- static int reverseNumber(int number)
- {
- return number * (-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement