Created
April 6, 2017 21:24
-
-
Save Reflej0/a242df9072534417c2cd3e562b785867 to your computer and use it in GitHub Desktop.
Algoritmo en C# para contar las palabras y caracteres dentro de una frase.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class Frase | |
{ | |
public static int[] PalabrasCaracteres(string frase){ | |
int palabras = 0; | |
int caracterestotales = 0; | |
for (int i = 0; i < frase.Length; i++) | |
{ | |
if (frase[i] == ' ' || frase[i] == '.') | |
{ | |
palabras++; | |
} | |
} | |
int[] PalabrasCaracteres = new int[2]; | |
caracterestotales = frase.Length - palabras; | |
PalabrasCaracteres[0] = palabras; | |
PalabrasCaracteres[1] = caracterestotales ; | |
return PalabrasCaracteres; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Ingrese una frase"); | |
string frase = Console.ReadLine(); | |
int[] resultado = Frase.PalabrasCaracteres(frase); | |
Console.WriteLine("La frase tiene {0} palabras", resultado[0]); | |
Console.WriteLine("La frase tiene {0} caracteres", resultado[1]); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment