Name Initials
Gets the initials of a full name.
- Level
- Beginner
- Topic:
- Text
- Concepts:
- Input & output
- Text
- Para
- Logic
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Remembering the previous letter tells you where each word starts. The condition joins two comparisons with Y, and Mayusculas capitalizes each initial.
Code
Algoritmo Iniciales Definir nombre, iniciales, letra, anterior Como Caracter Definir i Como Entero Escribir "Tu nombre completo:" Leer nombre iniciales <- "" anterior <- " " Para i <- 1 Hasta Longitud(nombre) Hacer letra <- Subcadena(nombre, i, i) // Una palabra empieza donde antes había un espacio Si anterior = " " Y letra <> " " Entonces iniciales <- iniciales + Mayusculas(letra) + "." FinSi anterior <- letra FinPara Escribir "Tus iniciales son: ", inicialesFinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Tu nombre completo:User answer: maría josé pérezTus iniciales son: M.J.P.
Challenge
Count how many words the name has and show it at the end.
Show hint
Add 1 to a counter every time you add an initial.
Related examples
Palindromes
Checks whether a phrase reads the same forwards and backwards.
IntermediateBubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
IntermediateInsertion Sort
Inserts each number among the sorted ones, like arranging cards in your hand.
Intermediate