Hola món

Un programa "hola món" és un programa d'ordinador que simplement imprimeix el text "Hola, món!" (en anglès "Hello, world!") a un dispositiu de sortida (normalment el monitor). En algunes tradicions, especialment en el món anglosaxó, és el primer exercici típic per a estudiants d'un llenguatge de programació.
Exemples
En Ada
<source lang="ada">
with Text_Io;
use Text_Io;
procedure Hola_Mon is
begin
Put_Line("Hola món!");
end Hola_Mon;
</source>
En BASH
<source lang="bash">
- !/bin/bash
echo "Hola, món!" </source>
En BASIC
PRINT "Hola, món!"
En Brainfuck
++++++++++
[
>+++++++>+++++++++++>+++>+<<<<-
] Bucle: inicialitza posicions d'(1) a (4) amb valors ASCII propers als necessitats
(1) per majúscules 110; (2) per minúscules 70; (3) per l'espai 32; (4) per nova línia 10
>++. escriu 'H'
>+. escriu 'o'
---. 'l'
-----------. 'a'
>++. espai
<<+++++. 'M'
>++++++++++++++. 'o' (sense accent per limitacions tècniques)
-. 'n'
>+. '!'
>. nova línia
Limitació: A Brainfuck els valors de cada byte van des de -128 a 127, només els valors positius codifiquen caràcters ASCII, per tant no es poden esciure caràcters d'ASCII extens com 'ó'.
El programa també es pot escriure sense comentaris ni salts de línia:
++++++++++[>+++++++>+++++++++++>+++>+<<<<-]>++.>+.---. -----------.>++.<<+++++.>++++++++++++++.-.>+.>.
En C
<source lang="c">
- include <stdio.h>
main() {
printf("Hola, món!\n");
} </source> o, en els estàndards actuals: <source lang="c">
- include <stdio.h>
int main(void) {
printf("hola, món\n");
return 0;
} </source>
En C++
<source lang="cpp">
- include <iostream>
main(void) {
std::cout << "Hola món!" << std::endl;
} </source> Encara que també es pot escriure així: <source lang="cpp">
- include <iostream>
using namespace std; int main() {
cout << "Hola món!" << endl;
} </source>
En COBOL
<source lang="cobol">
IDENTIFICATION DIVISION.
Program-Id. Hola-Món.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
Main.
DISPLAY "Hola Món!".
STOP RUN.
</source>
En C#
<source lang="CSharp">
using System;
class MainClass
{
public static void Main()
{
Console.WriteLine("HOLA, MÓN!");
}
}
</source>
En Fortran
<source lang="fortran">
PROGRAM HOLA
WRITE (*,100)
STOP
100 FORMAT (' Hola, món! ' /)
END
</source> o, en la versió Fortran77, <source lang="fortran">
PROGRAM HOLA
PRINT*, 'Hola, món!'
END
</source>
En HTML
<source lang=html4strict>
<html> <head> <title>Hola, món!</title> </head> <body>
hola, món!
</body> </html>
</source>
En Java
<source lang="java">
public class HolaMon {
public static void main(String[] args) {
System.out.println("Hola, món!");
}
}</source>
En JavaScript
<source lang="javascript">
document.write('Hola, món!');
</source> o amb una alerta <source lang="javascript">
alert('Hola, món!');
</source> que, dins una pàgina web (en HTML) quedaria <source lang="html4strict">
<html> <head> <title>Hola, món!</title> </head> <body>
<script language="JavaScript"> </script>
</body> </html>
</source> o bé <source lang="html4strict">
<html> <head> <title>Hola, món!</title> </head> <body> <script language="JavaScript"> </script> </body> </html>
</source>
En LaTeX
<source lang="latex"> \documentclass{article} \begin{document} Hola m\'on! \end{document} </source>
En LOGO
ESCRIU [Hola, món!]
En Pascal
<source lang="Pascal">
program hola_mon;
begin
writeln('Hola, món!');
end.
</source>
En Perl
<source lang="perl"> #!/usr/bin/perl
print "Hola món!\n" </source>
En PHP
<source lang="php">
<?php
echo "Hola, món";
?>
</source> o bé: <source lang="php">
<?php
print "Hola, món";
?>
</source>
que, dins una pàgina web (en HTML) quedaria
<html> <head> <title>Hola, món!</title> </head> <body> <p> <?php echo "Hola, món"; ?> </p> </body> </html>
En Python
<source lang="python">
print "Hola món"
</source>
En Seed7
$ include "seed7_05.s7i";
const proc: main is func
begin
writeln("Hola_món!");
end func;
En TeX
<source lang="latex"> Hola m\'on! \bye </source>
En VBScript
DOCUMENT.WRITE('Hola, món!')
que, dins una pàgina web (en HTML) quedaria
<html>
<body>
<script language="VBScript">
DOCUMENT.WRITE('Hola, món!')
</script>
</body>
</html>
Enllaços externs
- Llista més completa als Viquillibres anglòfons. (anglès)