En esta sección se resolverán dudas sobre C sharp, el lenguaje de programación de Microsoft, compatible con Unity
Moderator: julianmartinez16
-
xacarana
- Site Admin
- Posts: 1213
- Joined: Fri Jan 15, 2016 6:13 pm
Post
by xacarana » Wed Aug 31, 2016 10:40 am
Tarea:
Realizar, el procedimiento, para leer los siguientes tipos de datos
- bool
- byte
- char
- int
- long
- float
- double
- string
Lea correctamente los datos y realice algunas operaciones básicas con ellos, publique en este post los resultados.
Pida un valor entero al usuario y luego, clacule si el número que ingreso el usuario es par o es impar.
Ejemplo
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int x;
string dato;
Console.WriteLine("Ingrese un dato entero");
dato = Console.ReadLine();
if (int.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Andrés Bedoya Tobón
Profesor
"I only smile in the dark, I only smile when it's complicated" Raybiez
-
pipevarela98
- Posts: 27
- Joined: Fri Jul 22, 2016 10:20 am
Post
by pipevarela98 » Fri Sep 02, 2016 12:10 am
Tarea Lectura de datos
Code: Select all
//PARA INT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//declaración de variables
int x;
string dato;
//pedir datos
Console.WriteLine("ingrese numero entero");
dato = Console.ReadLine();
//operación
if (int.TryParse(dato, out x))
{
if (x%2==0)
{
Console.WriteLine("es par");
}
else
{
Console.WriteLine("no es par");
}
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
________________________________________________________________________________
//PARA DOUBLE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
// declaración variables
double x;
string dato;
//pedir datos
Console.WriteLine("ingrese numero");
dato = Console.ReadLine();
//operación
if (double.TryParse(dato, out x))
{
Console.WriteLine(2 * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
________________________________________________________________________________
//PARA BYTE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//Declaración variables
byte x;
string dato;
//pedir datos
Console.WriteLine("ingrese numero");
dato = Console.ReadLine();
//operacion
if (byte.TryParse(dato, out x))
{
Console.WriteLine((x * 6) / 2);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
________________________________________________________________________________
//PARA LONG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//declaración variables
long x;
string dato;
//pedir datos
Console.WriteLine("ingrese numero");
dato = Console.ReadLine();
//operación
if (long.TryParse(dato, out x))
{
Console.WriteLine((x * 10) / 2);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
________________________________________________________________________________
//PARA FLOAT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//declaración variables
float x;
string dato;
//pedir datos
Console.WriteLine("ingrese numero");
dato = Console.ReadLine();
//operación
if (float.TryParse(dato, out x))
{
Console.WriteLine((x * 10) / 4);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
________________________________________________________________________________
//PARA CHAR
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//Declaración variable
char L;
string dato;
//pedir datos
Console.WriteLine("ingrese letra");
dato = Console.ReadLine();
//operación
if (char.TryParse(dato, out L))
{
if (Char.IsLetter(L))
{
if (Char.IsLower(L))
{
Console.WriteLine("La letra es minuscula");
}
else
{
Console.WriteLine("La letra es mayuscula");
}
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
}
Console.ReadKey();
}
}
}
________________________________________________________________________________
//PARA BOOL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//Declaración variables
int num;
bool R = false;
//pedir datos
Console.WriteLine("Ingrese un numero: \n True: PAR \n False: IMPAR");
//Operación
num = int.Parse(Console.ReadLine());
{
if (num % 2 == 0 && R == false)
{
R = true;
Console.WriteLine(R);
}
else
{
Console.WriteLine(R);
}
}
Console.ReadKey();
}
}
}
__________________________________________________________
//PARA STRING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TAREA_Lectura_de_datos
{
class Program
{
static void Main(string[] args)
{
//Declaración variables
string usuario;
//pedir datos
Console.WriteLine("Por favor ingrese su usuario: ");
usuario = Console.ReadLine();
//operación
{
Console.WriteLine("hola " + usuario + " gracias por ingresar");
}
Console.ReadKey();
}
}
}
Juan Felipe Varela
Ing. en Diseño de Ent. Digital
Universidad Pontificia Bolivariana
2016
-
jimmy
- Posts: 54
- Joined: Fri Jul 22, 2016 10:51 am
Post
by jimmy » Fri Sep 02, 2016 1:54 am
como no entendía muy bien el uso del if/else , me puse un reto con este y utilice el dato float , investigue en internet un poco la manera de sacar el promedio de una nota de un estudiante.. algo básico, pero para mi no tanto.
PARA FLOAT
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string Nombre;
float x;
float calificacion1=0, calificacion2=0, promedio;
Console.WriteLine("ingrese nombre del alumno");
Nombre = Console.ReadLine();
Console.WriteLine("ingresa calificacion 1");
x =float.Parse(Console.ReadLine());
if(x<10.1){
calificacion1 = x;
}
else{
Console.WriteLine("captura una calificacion correcta");
}
x = float.Parse(Console.ReadLine());
Console.WriteLine("ingresa calificacion 2");
if (x < 10.1)
{
calificacion2 = x;
}
else
{
Console.WriteLine("captura una calificacion crrecta");
}
promedio = (calificacion1 + calificacion2) / 2;
Console.WriteLine(Nombre + " tu nota es" + promedio);
if (promedio>6)//true
{
Console.WriteLine("aprobaste");
}
else
{
Console.WriteLine("reprobaste");
}
Console.ReadKey();
}
}
}
PARA INT
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int n;
String Dato;
Console.Write("ingrese numero entero");
n = Convert.ToInt32(Console.ReadLine());
if(n % 2 == 0)
{
Console.WriteLine("el numero es par");
}
else
{
Console.WriteLine("el numero es impar");
}
Console.ReadKey();
}
}
}
PARA DOUBLE
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
double x;
string dato;
Console.WriteLine("ingrese numero");
dato = Console.ReadLine();
if (double.TryParse(dato, out x))
{
Console.WriteLine(8 / x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA BYTE
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
byte x;
string dato;
Console.WriteLine("ingrese numero");
dato = Console.ReadLine();
if (byte.TryParse(dato, out x))
{
Console.WriteLine((4 * x) / 3);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA CHAR
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
char m;
string dato;
Console.WriteLine("ingrese letra");
dato = Console.ReadLine();
if (char.TryParse(dato, out m))
{
if (Char.IsLetter(m))
{
if (Char.IsLower(m))
{
Console.WriteLine("La letra es minuscula");
}
else
{
Console.WriteLine("La letra es mayuscula");
}
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
}
Console.ReadKey();
PARA STRING
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
string usuario;
Console.WriteLine("ingrese su nombre: ");
usuario = Console.ReadLine();
{
Console.WriteLine("hola "+ usuario + "es todo un gusto conocerlo");
}
Console.ReadKey();
}
}
PARA LONG
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
long x;
string dato;
Console.WriteLine("Ingrese un dato entero");
dato = Console.ReadLine();
if (long.TryParse(dato, out x))
{
Console.WriteLine((x*x)/5);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
juan jose jimenez tobon - Case : Miercoles - viernes 10:00 am a 12:00 am fundamentos de programación
-
ManuelTheo
- Posts: 22
- Joined: Fri Jul 22, 2016 10:11 am
Post
by ManuelTheo » Fri Sep 02, 2016 9:02 am
Para Int
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int x;
string dato;
Console.WriteLine("Ingrese un dato entero");
dato = Console.ReadLine();
if (int.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para bool
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
bool x;
string dato;
Console.WriteLine("Ingrese un dato booleano");
dato = Console.ReadLine();
if (bool.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para Byte
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
byte x;
string dato;
Console.WriteLine("Ingrese un dato");
dato = Console.ReadLine();
if (byte.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para char
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
char x;
string dato;
Console.WriteLine("Ingrese un dato");
dato = Console.ReadLine();
if (char.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para Long
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
long x;
string dato;
Console.WriteLine("Ingrese un dato");
dato = Console.ReadLine();
if (long.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para Float
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
float x;
string dato;
Console.WriteLine("Ingrese un dato flotante");
dato = Console.ReadLine();
if (float.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para double
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
double x;
string dato;
Console.WriteLine("Ingrese un dato");
dato = Console.ReadLine();
if (double.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Para string
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string dato;
Console.WriteLine("Ingrese un dato");
dato = Console.ReadLine();
Console.ReadKey();
}
}
}
-
maxiferado
- Posts: 43
- Joined: Fri Jul 22, 2016 10:17 am
Post
by maxiferado » Fri Sep 02, 2016 9:37 am
PARA BOOL
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
bool x;
string dato;
Console.WriteLine("Ingrese un dato booleano");
dato = Console.ReadLine();
if (bool.TryParse(dato, out x))
{
Console.WriteLine(x*x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA BYTE
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
byte x;
string dato;
Console.WriteLine("Ingresar un numero");
dato = Console.ReadLine();
if (byte.TryParse(dato, out x))
{
Console.WriteLine((80*x) / 4);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA CHAR
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
char m;
string dato;
Console.WriteLine("Ingrese una Letra");
dato = Console.ReadLine();
if (char.TryParse(dato, out m))
{
if (Char.IsLetter(m))
{
if (Char.IsHigher(m))
{
Console.WriteLine("La Letra es Mayuscula");
}
else
{
Console.WriteLine("La Letra es Minuscula");
}
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
}
Console.ReadKey();
PARA INT
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int x;
string dato;
Console.Write("Ingresar un Numero Entero");
x = Convert.ToInt32(Console.ReadLine());
if(x % 2 =! 0)
{
Console.WriteLine("El Numero es Impar");
}
else
{
Console.WriteLine("El Numero es Par");
}
Console.ReadKey();
}
}
}
PARA LONG
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
long x;
string dato;
Console.WriteLine("Ingrese un Dato");
dato = Console.ReadLine();
if (long.TryParse(dato, out x))
{
Console.WriteLine(x*x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA FLOAT
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
float x;
string dato;
Console.WriteLine("Ingrese un dato flotante");
dato = Console.ReadLine();
if (float.TryParse(dato, out x))
{
Console.WriteLine(x * x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA DOUBLE
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
double x;
string dato;
Console.WriteLine("Ingresar un Numero");
dato = Console.ReadLine();
if (double.TryParse(dato, out x))
{
Console.WriteLine(100 / x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
PARA STRING
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
string Nombre;
Console.WriteLine("Como te llamas? ");
usuario = Console.ReadLine();
{
Console.WriteLine("Bienvenido al mundo " + Nombre " En el momento estamos en construcción");
}
Console.ReadKey();
}
}
Diego Alejandro Jaime Baron
Estudiante de entretenimiento digital, 3 semestre clase 10-12

-
estebanc1503
- Posts: 56
- Joined: Fri Jul 22, 2016 10:06 am
Post
by estebanc1503 » Fri Sep 02, 2016 9:43 am
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
bool x;
string dato;
Console.WriteLine("Ingrese un dato booleano");
dato = Console.ReadLine();
if (bool.TryParse(dato, out x))
{
Console.WriteLine((x+x)/x);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
-
estebanc1503
- Posts: 56
- Joined: Fri Jul 22, 2016 10:06 am
Post
by estebanc1503 » Fri Sep 02, 2016 9:44 am
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
byte x;
string dato;
Console.WriteLine("Ingresar un numero");
dato = Console.ReadLine();
if (byte.TryParse(dato, out x))
{
Console.WriteLine((x*x) / 4);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}
Last edited by
estebanc1503 on Fri Sep 02, 2016 9:51 am, edited 2 times in total.
-
estebanc1503
- Posts: 56
- Joined: Fri Jul 22, 2016 10:06 am
Post
by estebanc1503 » Fri Sep 02, 2016 9:50 am
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
char m;
string dato;
Console.WriteLine("Ingrese una Letra");
dato = Console.ReadLine();
if (char.TryParse(dato, out p))
{
if (Char.IsLetter(p))
{
if (Char.IsHigher(p))
{
Console.WriteLine("La Letra es Mayuscula");
}
else
{
Console.WriteLine("La Letra es Minuscula");
}
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
}
Console.ReadKey();
-
estebanc1503
- Posts: 56
- Joined: Fri Jul 22, 2016 10:06 am
Post
by estebanc1503 » Fri Sep 02, 2016 9:52 am
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int x;
string dato;
Console.Write("Ingresar un Numero Entero");
x = Convert.ToInt32(Console.ReadLine());
if(x % 1 =! 0)
{
Console.WriteLine("El Numero es Impar");
}
else
{
Console.WriteLine("El Numero es Par");
}
Console.ReadKey();
}
}
}
-
estebanc1503
- Posts: 56
- Joined: Fri Jul 22, 2016 10:06 am
Post
by estebanc1503 » Fri Sep 02, 2016 9:54 am
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
long x;
string dato;
Console.WriteLine("Ingrese un Dato");
dato = Console.ReadLine();
if (long.TryParse(dato, out x))
{
Console.WriteLine((x*x)+6);
}
else
{
Console.WriteLine("Error en la lectura de datos");
}
Console.ReadKey();
}
}
}