wingman007 icon

MagSolutionsExample2023

wingman007 | PRO | 10/28/23 10:38:59 AM UTC (Edited) | 0 ⭐ | 1569 👁️ | Never ⏰ | []
C# |

5.36 KB

|

None

|

0 👍

/

0 👎

// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");
// Zad 1.
//Console.WriteLine("2011 to BIN {0}.", Convert.ToString(2093, 2));
//Console.WriteLine("2011 to OCT {0}.", Convert.ToString(2093, 8));
//Console.WriteLine("2011 to HEX {0}.", Convert.ToString(2093, 16));
 
 
// Test 1 - 2 I
//double x = 3.4, y = 5.6, z = 7.8;
 
//Console.WriteLine(
//    ((Math.Pow(x, 7.0) * y * z) - 3.3 * Math.Abs(x + Math.Pow(y, 1/4.0))) /
//    Math.Pow(10.0, 7.0) + Math.Sqrt(Math.Log(4.0))
//);
 
 
// Zad 36 d
//int x = 2;
//int y = 3;
//int z = 4;
 
//Console.WriteLine(x > 0 && y > 0 && z > 0);
 
// zad 102.
 
//int a1, a2, a3, a4, a5, a6;
 
//for (int number = 0; number <= 999999; number++)
//{
//    a1 = (number / 100000);
//    a2 = (number / 10000) % 10;
//    a3 = ((number / 1000) % 10);
//    a4 = ((number / 100) % 10);
//    a5 = ((number / 10) % 10);
//    a6 = number % 10;
 
//    if (a1 + a2 + a3 == a4 + a5 + a6)
//    {
//        Console.WriteLine($"{number} is a lucky number");
//    }
//}
 
// zad 164
//int[] A = {2, 2};
//int[] B = {3, 4};
//int[] C = {5, 6};
 
//double a = Math.Sqrt(Math.Pow((B[0] - A[0]), 2) + Math.Pow((B[1] - A[1]), 2));
//Console.WriteLine(a);
//double b = Math.Sqrt(Math.Pow((C[0] - B[0]), 2) + Math.Pow((C[1] - B[1]), 2));
//Console.WriteLine(b);
//double c = Math.Sqrt(Math.Pow((C[0] - A[0]), 2) + Math.Pow((C[1] - A[1]), 2));
//Console.WriteLine(c);
 
//if (a + b > c && a + c > b && b + c > a)
//{
//    Console.WriteLine("This is a triangle");
//    double s = (a + b + c) / 2;
//    double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
//    Console.WriteLine($"The area is {area}");
//}
//else
//{
//    Console.WriteLine("Thi si snot a triangle");
//}
 
 
// Zad 405
int n = 0;
bool isNumber = false;
do
{
    Console.Write("Please, enter the lenght of the array [2,25] ");
    n = int.Parse(Console.ReadLine());
} while (n < 2 || n > 25);
//    isNumber = int.TryParse(Console.ReadLine(), out n);
//} while (!isNumber || (n < 2 || n > 25));
 
int[] myArray = new int[n];
for (int i = 0; i < myArray.Length; i++)
{
    Console.Write($"Please enter a value for element myArrey[{i}] = ");
    myArray[i] = int.Parse(Console.ReadLine());
}
 
for (int i = 0; i < myArray.Length; i++)
{
    Console.WriteLine($"myArray[{i}] = {myArray[i]}");
}
 
int k = 0;
Console.Write("Please, enter k = ");
k = int.Parse(Console.ReadLine());
Console.WriteLine(Prod(myArray, k));
 
static int Prod(int[] myArray, int k)
{
    int sum = 0;
    for (int i = 0; i < myArray.Length; i++)
    {
        if (myArray[i] > 0 && myArray[i] < k)
        {
            sum += myArray[i];
        }
    }
    return sum;
}
 
int counter = 0;
int a1 = 0;
int a2 = 0;
int a3 = 0;
for (int i = 0; i < myArray.Length; i++)
{
    if (myArray[i] >= 100 && myArray[i] <= 666)
    {
        a1 = myArray[i] / 100;
        a2 = (myArray[i] / 10) % 10;
        a3 = myArray[i] % 10;
 
        //string numberString = myArray[i].ToString();
        //a1 = numberString[0];
        //a2 = numberString[1];
        //a3 = numberString[2];
 
        if ((a1 + a2 + a3) % 3 == 0)
        {
            counter++;
        }
    }
}
 
Console.WriteLine(counter);
 
 
// Zad 363
//Console.WriteLine(counter);
 
//char myChar = 'A';
//Console.WriteLine((int)myChar);
 
//string unicode = "&#1075;&#1088;&#1072;&#1072;";
//string result = unicode.Replace("&#1075;", "г");
 
//Console.WriteLine(result);
 
// ------------------------------------------
//Console.WriteLine("2010 to BIN {0}.", Convert.ToString(2010, 2));
//Console.WriteLine("2010 to OCT {0}.", Convert.ToString(2010, 8));
//Console.WriteLine("2010 to HEX {0}.", Convert.ToString(2010, 16));
 
double H = 2.3;
double R = 5.0;
Console.WriteLine("Surface s = {0}", 2 * Math.PI * R * H);
Console.WriteLine("Full Surface S = {0}", 2 * Math.PI * R * H + 2 * Math.PI * Math.Pow(R, 2));
 
// Zad 37 - 4
bool s = false;
bool t = true;
 
Console.WriteLine(!(s || t) && s || !t);
 
// Zad 99
double sum = 0;
for (int i = 1; i < 100000; i++)
{
    if (i % 2 == 0)
    {
        sum -= 1.0/i;
    }
    else
    {
        sum += 1.0 / i;
    }
}
 
Console.WriteLine(sum);
 
sum = 0;
 
for (int i = 100000; i >= 1; i--)
{
    if (i % 2 == 0)
    {
        sum -= 1.0 / i;
    }
    else
    {
        sum += 1.0 / i;
    }
}
 
Console.WriteLine(sum);
 
double sumPositive = 0;
double sumNegative = 0;
 
for (int i = 1; i <= 100000; i++)
{
    if (i % 2 == 0)
    {
        sumNegative -= 1.0 / i;
    }
    else
    {
        sumPositive += 1.0 / i;
    }
}
 
Console.WriteLine(sumNegative);
Console.WriteLine(sumPositive);
 
 
sumPositive = 0;
sumNegative = 0;
 
for (int i = 100000; i >= 1; i--)
{
    if (i % 2 == 0)
    {
        sumNegative -= 1.0 / i;
    }
    else
    {
        sumPositive += 1.0 / i;
    }
}
 
Console.WriteLine(sumNegative);
Console.WriteLine(sumPositive);
 
 
 
// Zad 163 zad 90
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int p = 6;
int q = -7;
 
// Console.WriteLine(a * x + b * y + c * z + d = 0);
 
for (int x = p; x < q; x++)
{
    for (int y = p; y < q; y++)
    {
        for (int z = p; z < q; z++)
        {
            if (a*x + b*y + c*z + d == 0)
            {
                Console.WriteLine($"x = {x} y = {y} z = {z}");
                Console.ReadKey(true);
            }
        }
    }
}
 

Comments