Skip to content
ExamplesEspañolWorkspace →

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

initials.psc · 17 lines
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: ", inicialesFinAlgoritmo

Flowchart

Each block in the flowchart matches one instruction in the code.

Algoritmo InicialesSíNoAlgoritmo InicialesAlgoritmo InicialesDefinir nombre, iniciales, letra, anterior Como CaracterDefinir nombre, iniciales,letra, anterior Como CaracterDefinir i Como EnteroDefinir i Como EnteroEscribir "Tu nombre completo:"Escribir "Tu nombre completo:"Leer nombreLeer nombreiniciales <- ""iniciales <- ""anterior <- " "anterior <- " "Para i <- 1 Hasta Longitud(nombre) HacerPara i <- 1 HastaLongitud(nombre)letra <- Subcadena(nombre, i, i)letra <- Subcadena(nombre, i,i)Si anterior = " " Y letra <> " " Entoncesanterior = " " Yletra <> " "iniciales <- iniciales + Mayusculas(letra) + "."iniciales <- iniciales +Mayusculas(letra) + "."anterior <- letraanterior <- letraEscribir "Tus iniciales son: ", inicialesEscribir "Tus iniciales son:", inicialesFinAlgoritmoFinAlgoritmo

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.

Open in Codoritmo
  • Palindromes

    Checks whether a phrase reads the same forwards and backwards.

    Intermediate
  • Bubble Sort

    Sorts random numbers by swapping neighbors, and stops as soon as they're in order.

    Intermediate
  • Insertion Sort

    Inserts each number among the sorted ones, like arranging cards in your hand.

    Intermediate