Untitled
Anonymous
csharp
02/28/2026 9:26 AM
6.6 KB
38
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication;
using System.Text;
using System.Threading.Tasks;
namespace Egzamin
{
public class Program
{
////
// Jaki będzie wynik działania poniższego kodu?
////
static void Main(string[] args)
{
char[,] tablica = UtworzTablice();
Zmien(tablica);
Wyswietl(tablica);
}
public static char[,] UtworzTablice()
{
char[,] tab = new char[5, 5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
tab[i, j] = '*';
}
}
return tab;
}
public static void Zmien(char[,] tab)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 5; j++)
{
if (j >= 2 - i && j <= 2 + i)
tab[i, j] = '#';
else
tab[i, j] = '*';
}
}
}
public static void Wyswietl(char[,] tab)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
Console.Write(tab[i, j] + " ");
}
Console.WriteLine();
}
}
//////
//// Jaki będzie wynik działania poniższego kodu?
//////
static void Main(string[] args)
{
string tekst = "Ala ma kota";
char[] znak = new char[11];
znak[2] = '!';
string zamieniony = Zamien(tekst, znak);
Console.WriteLine(Wyswietl(zamieniony));
}
private static string Zamien(string tekst, char[] znak, char a)
{
znak[2] = '!';
return Zamien(tekst, znak);
}
private static string Zamien(string tekst, char[] znak, int b = 2)
{
return tekst;
}
private static string Zamien(string tekst, char[] znak)
{
return tekst.Replace(tekst[2], znak[2]);
}
private static string Wyswietl(string tekst)
{
string w = "";
for (int i = tekst.Length - 1; i >= 0; i--)
{
w += tekst[i];
}
return w;
}
//////
//// Jaki będzie wynik działania gdy użytkownik wprowadzi liczbę 131?
//////
static void Main(string[] args)
{
Console.WriteLine("Podaj liczbę:");
int liczba = int.Parse(Console.ReadLine());
string wynikA = FunctionA(liczba);
string wynikB = FunctionB(liczba);
Console.WriteLine(wynikA);
Console.WriteLine();
Console.WriteLine(wynikB);
}
public static string FunctionA(int liczba)
{
if (liczba < 2)
{
return liczba.ToString();
}
return FunctionA(liczba / 2) + (liczba % 2);
}
public static string FunctionB(int liczba)
{
if (liczba == 0)
return "0";
int n = liczba;
string wynik = "";
while (n > 0)
{
wynik = n % 2 + wynik;
n /= 2;
}
return wynik;
}
//////
//// Jaki będzie wynik działania poniższego kodu gdy użytkownik wprowadzi klawisz '2'?
//////
static void Main(string[] args)
{
Console.Clear();
Console.WriteLine("=== MENU (1-6) ===");
Console.WriteLine("1) Kalkulator");
Console.WriteLine("2) Bazy");
Console.WriteLine("3) Teoria");
Console.WriteLine("4) Egzamin");
Console.WriteLine("5) Zakończ");
Console.WriteLine();
Console.Write("Wybierz opcję (1-5): ");
Console.WriteLine();
ConsoleKeyInfo key = Console.ReadKey();
switch (key.Key)
{
case ConsoleKey.D1:
Console.WriteLine("Kalkulator");
break;
case ConsoleKey.D2:
Console.WriteLine("Egzamin");
break;
case ConsoleKey.D3:
Console.WriteLine("Teoria");
break;
case ConsoleKey.D4:
Console.WriteLine("Egzamin");
break;
case ConsoleKey.D5:
Environment.Exit(0);
return;
}
}
}
}
Editor is loading...
Leave a Comment