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 programcic
- {
- class Program
- {
- static void Obrnuti() // funkcija da obrne ime i prezime koje si uneo, opcija 2 sa testa
- {
- Console.WriteLine("Unesi ime");
- string ime = Console.ReadLine();
- Console.WriteLine("Unesi prezime:");
- string prezime = Console.ReadLine();
- string obrnuti = ime + prezime;
- string djoka = "";
- for(int i = obrnuti.Length-1; i>=0; i--)
- {
- djoka = djoka + obrnuti[i];
- }
- Console.WriteLine("Obrnuti je:");
- foreach(var s in djoka)
- {
- Console.Write(s);
- }
- }
- static void Proveri() // funkcija da proveri da li je proizvod godine,meseca i dana deljiva sa unetim brojem
- {
- int g, m, d;
- int broj;
- Console.WriteLine("Unesi godinu:");
- g = int.Parse(Console.ReadLine());
- Console.WriteLine("Unesi mesec:");
- m = int.Parse(Console.ReadLine());
- Console.WriteLine("Unesi dan:");
- d = int.Parse(Console.ReadLine());
- Console.WriteLine("Unesi broj:");
- broj = int.Parse(Console.ReadLine());
- int proizvod = g * m * d;
- if (proizvod % broj == 0)
- {
- Console.WriteLine("Deljiv je:");
- }
- else
- {
- Console.WriteLine("nije deljiv:");
- }
- }
- static void UnosNiza() funkcija za unos nekog random niza
- {
- Console.WriteLine("Unesite clanove niza:");
- int n = int.Parse(Console.ReadLine());
- int[] niz = new int[n];
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine("element[{0}] =", i);
- niz[i] = int.Parse(Console.ReadLine());
- }
- Sort(niz); // poziv funkcije sort
- }
- static void Sort(int[] arr) // funkcija za sortiranje bilo kog niza
- {
- Console.WriteLine("Sortiran niz je:");
- for (int i = 0; i < arr.Length; i++)
- {
- for (int j = i + 1; j < arr.Length; j++)
- {
- if (arr[i] > arr[j])
- {
- int tmp = arr[i];
- arr[i] = arr[j];
- arr[j] = tmp;
- }
- }
- }
- foreach(int b in arr)
- {
- Console.WriteLine("{0}\t", b);
- }
- }
- static void UnosMatrice() // funkcija za unos matrice A i B
- {
- Console.WriteLine("Unesi dimenziju matrice:");
- int n = int.Parse(Console.ReadLine());
- int[,] matrica_A = new int[n, n];
- Console.WriteLine("Unesi clanove matrice:");
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.WriteLine("element[{0},{1}]", i, j);
- matrica_A[i, j] = int.Parse(Console.ReadLine());
- }
- }
- Console.WriteLine("Matrica A je :"); // ispis matrice A
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write("{0}\t", matrica_A[i, j]);
- }
- Console.WriteLine();
- }
- int[,] matrica_B = new int[n, n];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- matrica_B[i, j] = matrica_A[i, j] * j; //logika za punjenje matrice B
- }
- }
- Console.WriteLine("Matrica B je :"); // ispis matrice B
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write("{0}\t", matrica_B[i, j]);
- }
- Console.WriteLine();
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- matrica_B[i, j] += matrica_A[i, j]; // sabiranje A i B
- }
- }
- Console.WriteLine("Zbir je:");
- for ( int i = 0; i < n; i++) //ispis A i B
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write("{0}\t", matrica_B[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Meni");
- Console.WriteLine("1. Unesite niz i sortirajte ga:");
- Console.WriteLine("2. Saberite 2 matrice, pri čemu se B dobija na posebni nacin:");
- Console.WriteLine("3. Proverite da li je proizvod godine,meseca i dana deljivo 3:");
- Console.WriteLine("4. Obrni ime i prezime koje si uneo:");
- Console.WriteLine("5. Za izlaz:");
- while (true)
- {
- Console.WriteLine("Unesite opciju koju zelite:");
- int option = int.Parse(Console.ReadLine());
- switch (option)
- {
- case 1: UnosNiza(); break; // POZIVANJE FUNKCIJA U MAIN-U i kraj programa
- case 2: UnosMatrice(); break;
- case 3: Proveri(); break;
- case 4: Obrnuti(); break;
- case 5: return;
- default: Console.WriteLine("Probaj opet"); break;
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement