first commit

This commit is contained in:
2021-09-02 08:31:01 -03:00
commit a065d198ad
22 changed files with 1521 additions and 0 deletions

View File

@ -0,0 +1,36 @@
using System;
namespace exercicios
{
class Exercicio1{
public static void Init()
{
string nome;
Console.WriteLine("Write a Name");
nome = Console.ReadLine();
double media = lerNota();
Console.WriteLine("Student: {0}, Avg. Grade: {1:N2}",nome,media);
Console.WriteLine(media > 7 ? "PASS" : "FAIL");
}
static double lerNota()
{
float n1,n2;
Console.WriteLine("Insert the grades (2)...");
n1 = float.Parse(Console.ReadLine());
n2 = float.Parse(Console.ReadLine());
return calcularMedia(n1,n2);
}
static float calcularMedia(float i, float i2)
{
return ((i+i2)/2);
}
}
}

View File

@ -0,0 +1,27 @@
using System;
namespace exercicios
{
class Exercicio2{
public static void Init()
{
int n;
Console.WriteLine("Insert a value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("{0}! = {1}",n,calcularFatorial(n));
}
static int calcularFatorial(int n)
{
int fat = 1;
for(int i = 1; i <= n; i++)
{
fat *= i;
}
return fat;
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace exercicios
{
public class Exercicio3{
public static void Init()
{
double i,i2;
Console.WriteLine("Insert the values (2)...");
i = double.Parse(Console.ReadLine());
i2 = double.Parse(Console.ReadLine());
diferenca(i,i2);
}
static void diferenca(double n, double n2)
{
double val = 0;
val = n > n2 ? n - n2 : n2 - n;
Console.WriteLine("The result being zero means the numbers are equal.");
Console.WriteLine("The difference between {0:N2} and {1:N2} is {2:N2}",
n,n2,val);
}
}
}

View File

@ -0,0 +1,63 @@
using System;
namespace exercicios
{
class Exercicio4{
public static void Init()
{
double a,b,c;
Console.WriteLine("Insert the triangle's dimensions (A,B,C)");
a = double.Parse(Console.ReadLine());
b = double.Parse(Console.ReadLine());
c = double.Parse(Console.ReadLine());
if(a < (b+c) && b < (a+c) && c < (a+b))
{
Console.WriteLine(TriEquil(a,b,c) == true ?
"Equilateral" : TriIso(a,b,c) == true ?
"Isosceles" : TriEsc(a,b,c) == true ?
"Scalene" : "N. A.");
}
else
{
Console.WriteLine("Not a triangle.");
}
}
static bool TriEquil(double a, double b, double c)
{
if (a == b && b == c)
{
return true;
}
else
{
return false;
}
}
static bool TriIso(double a, double b, double c)
{
if (a == b || a == c || b == c)
{
return true;
}
else
{
return false;
}
}
static bool TriEsc(double a, double b, double c)
{
if((TriIso(a,b,c) && TriEquil(a,b,c)) == false)
{
return true;
}
else {return false;}
}
}
}

View File

@ -0,0 +1,106 @@
using System;
using System.Reflection;
namespace exercicios
{
class Exercicio5
{
public static void Init()
{
string sel = "";
Console.WriteLine("Select an operation:"+
"\n1 - Sum"+
"\n2 - Subtract"+
"\n3 - Divide"+
"\n4 - Multiply"+
"\n5 - Div. Remains"+
"\n6 - Double"+
"\n7 - Squared"+
"\n8 - Cubed"+
"\n9 - Square Root"+
"\n0 - Exit");
sel = Console.ReadLine();
if(sel != "0"){
Console.WriteLine("Insert a value and press Enter (2)");
Type typesPrograma = typeof(Exercicio5);
MethodInfo aInvocar = typesPrograma.GetMethod(
"op"+sel, BindingFlags.Static | BindingFlags.NonPublic);
aInvocar.Invoke(null, null);
}
}
static void op1()
{
int i, i2;
i = int.Parse(Console.ReadLine());
i2 = int.Parse(Console.ReadLine());
Console.WriteLine("{0} + {1} = {2}",i,i2,i+i2);
}
static void op2()
{
int i, i2;
i = int.Parse(Console.ReadLine());
i2 = int.Parse(Console.ReadLine());
Console.WriteLine("{0} - {1} = {2}",i,i2,i-i2);
}
static void op3()
{
int i, i2;
i = int.Parse(Console.ReadLine());
i2 = int.Parse(Console.ReadLine());
Console.WriteLine("{0} / {1} = {2:N2}",i,i2,(double)i/i2);
}
static void op4()
{
int i, i2;
i = int.Parse(Console.ReadLine());
i2 = int.Parse(Console.ReadLine());
Console.WriteLine("{0} * {1} = {2}",i,i2,i*i2);
}
static void op5()
{
int i, i2;
i = int.Parse(Console.ReadLine());
i2 = int.Parse(Console.ReadLine());
Console.WriteLine("{0} % {1} = {2}",i,i2,(double)i%i2);
}
static void op6()
{
int i;
i = int.Parse(Console.ReadLine());
Console.WriteLine("{0}*2 = {1}",i,i*2);
}
static void op7()
{
int i;
i = int.Parse(Console.ReadLine());
Console.WriteLine("{0}^2 = {1}",i,i*i);
}
static void op8()
{
int i;
i = int.Parse(Console.ReadLine());
Console.WriteLine("{0}^3 = {1}",i,i*i*i);
}
static void op9()
{
int i;
i = int.Parse(Console.ReadLine());
Console.WriteLine("Sqrt({0}) = {1}",i,Math.Sqrt(i));
}
static void op10()
{
}
}
}

View File

@ -0,0 +1,36 @@
using System;
namespace exercicios
{
public class Exercicio6
{
public static void Init()
{
string sexo;
float i_altura;
Console.WriteLine("Biological sex (male/female):");
sexo = Console.ReadLine();
Console.WriteLine("Height (in meters):");
i_altura = float.Parse(Console.ReadLine());
Console.WriteLine("\n{0:N2} is the ideal weight for a {1}, with the height of: {2}m",
calcularPesoIdeal(i_altura,sexo),sexo,i_altura);
}
static float calcularPesoIdeal(float i, string s)
{
switch(s.ToLower())
{
case "male":
return (72.7f*i)-58f;
case "female":
return (62.1f*i)-44.7f;
default:
Console.WriteLine("\nWrite a valid value!");
break;
}
return 0;
}
}
}

View File

@ -0,0 +1,31 @@
using System;
namespace exercicios
{
public class Exercicio7
{
public static void Init()
{
float x,y;
Console.WriteLine("Write the values for X and Y");
x = float.Parse(Console.ReadLine());
y = float.Parse(Console.ReadLine());
Console.WriteLine("(x{0:N2};y{1:N2}) is in quadrant {2}",
x,y,verificaQuadrante(x,y));
}
static char verificaQuadrante(float x, float y)
{
if (x > 0)
{
if(y >= 0)return '1';
else if(y < 0)return '4';
}
else if (x < 0)
{
if(y >= 0)return '2';
else if(y < 0)return '3';
}
return 'N';
}
}
}

View File

@ -0,0 +1,25 @@
using System;
namespace exercicios
{
class Exercicio8
{
public static void Init()
{
float b,a;
Console.WriteLine("Hypotenuse Calculator\nInsert the values for b (triangle base) & a (triangle height).");
b = float.Parse(Console.ReadLine());
a = float.Parse(Console.ReadLine());
Console.WriteLine("\nTriangle base {0}, Height {1}, Hypotenuse {2:N2}",
b,
a,
hipotenusa(a,b));
}
static float hipotenusa(float b, float a)
{
return (float)Math.Sqrt((b*b)+(a*a));
}
}
}