Page 1 of 14 12311 ... LastLast
Results 1 to 10 of 297

Thread: "Hello Ubuntu" in every programming language

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Location
    Australia
    Beans
    1,097
    Distro
    Ubuntu 12.04 Precise Pangolin

    "Hello Ubuntu" in every programming language

    List made by pp., posted by LaRoza


    ================================================== ================================================== ===



    I've just been inspired by a webpage with 193 examples of "Hello World!" programs.

    I want to make something a just slightly more useful for the beginning programmer.

    Write the most concise, but clearly readable program (call it helloubuntu) according to this specification:
    1. Say: "Hi! What's your name? "
    2. User enters name.
    3. Say: "Hello, (username)! Welcome to Ubuntu!"
    You can also use a simple GUI, like a dialog box, to ask the question, input name, etc. Just make sure the code is elegant and easy-to-understand.

    You can use programming languages, markup languages, shell scripts, or even SQL statements.

    Try not to hog too many languages. Give other posters a fair go at posting their example too. If you are posting an alternative version of code for a language that has already been posted, mention that it is an alternative version.


    I'll start off:

    Ada (using normal fixed-length string)
    Code:
    with Ada.Text_IO;
    
    use Ada.Text_IO;
    
    procedure helloubuntu is
    	username : String(1..30);
    	lastchar : Integer;
    begin
    	Put_Line("Hi!  What's your name?");
    	Get_Line(username, lastchar);
    	Put_Line("Hello, " & username(1..lastchar) & "!  Welcome to Ubuntu!");
    end helloubuntu;
    Ada (using the 2005 standard's unbounded-string)
    Code:
    with Ada.Text_IO, Ada.Text_IO.Unbounded_IO, Ada.Strings.Unbounded;
    
    use Ada.Text_IO, Ada.Text_IO.Unbounded_IO, Ada.Strings.Unbounded;
    
    procedure helloubuntu is
    	username : Unbounded_String;
    begin
    	Put("Hi!  What's your name? ");
    	Get_Line(username);
    	Put_Line("Hello, " & username & "!  Welcome to Ubuntu!");
    end helloubuntu;
    Can we beat 193?
    Last edited by samjh; November 27th, 2010 at 02:29 AM.

  2. #2
    Join Date
    Jun 2006
    Beans
    47

    Re: "Hello Ubuntu" in every programming language

    BASH

    Code:
    echo -n "Hi whats your name? "
    read name
    echo "Hello $name. Welcome to Ubuntu"

  3. #3
    Join Date
    Dec 2005
    Beans
    527
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: "Hello Ubuntu" in every programming language

    C

    runningwithscissors came up with a better one. So here it is.
    Code:
    #include <stdio.h>
    
    int main()
    {
            char name[64];
            printf("Hi! What's your name? ");
            scanf("%s", &name);
            printf("Hello, %s! Welcome to Ubuntu (GNU)/Linux!\n", &name);
    
            return 0;
    }
    That is my really bad C one. Please criticize me via PM if you feel the need.
    Last edited by Note360; July 11th, 2007 at 01:47 AM. Reason: runningwithscissors came up with a simpler implementation

  4. #4
    Join Date
    May 2008
    Location
    Netherlands, Groningen
    Beans
    18
    Distro
    Ubuntu Studio 8.10 Intrepid Ibex

    Re: "Hello Ubuntu" in every programming language

    Quote Originally Posted by Note360 View Post
    C

    runningwithscissors came up with a better one. So here it is.
    Code:
    #include <stdio.h>
    
    int main()
    {
            char name[64];
            printf("Hi! What's your name? ");
            scanf("%s", &name);
            printf("Hello, %s! Welcome to Ubuntu (GNU)/Linux!\n", &name);
    
            return 0;
    }
    That is my really bad C one. Please criticize me via PM if you feel the need.
    Small mistake: you used
    Code:
    &name
    for the string to print, but that is incorrect, as it takes the adress-of the string array, not the array itself. So it needs to read:
    Code:
    #include <stdio.h>
    
    int main()
    {
            char name[64];
            printf("Hi! What's your name? ");
            scanf("%s", name);
            printf("Hello, %s! Welcome to Ubuntu (GNU)/Linux!\n", name);
    
            return 0;
    }
    (or alternatively: &name[0])
    Last edited by robheus; May 25th, 2008 at 08:40 AM.

  5. #5
    Join Date
    May 2007
    Location
    Alexandria, VA
    Beans
    25
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: "Hello Ubuntu" in every programming language

    Perl

    Code:
    Code:
    #!/usr/bin/perl
    
    use strict;
    
    print "Hi, What is your name? ";
    chomp( my $name = <STDIN> );
    $name = ucfirst(lc($name)); # make "name" -> "Name"
    print "Hello $name, Welcome to Ubuntu!\n";
    Result:
    Code:
    [{bulldog}~]$./name.pl
    Hi, What is your name? bULlDoG
    Hello Bulldog, Welcome to Ubuntu!
    [{bulldog}~]$

    * Side note http://www.99-bottles-of-beer.net/ has examples of `99 Bottle of Beer' in every language that I can think of ( and alot that I couldn't ) ... Gives beginners some experience with conditionals and loops as well
    Last edited by bulldog060; July 10th, 2007 at 05:26 PM.

  6. #6
    Join Date
    Aug 2012
    Beans
    1

    Re: "Hello Ubuntu" in every programming language

    Code:
    Code:
    #!/usr/bin/perl
    use strict;
    use ExtUtils::MakeMaker qw/prompt/;
    
    my $name = prompt("Hi, What is your name?");
    
    print "Hello \L\u$name\E, Welcome to Ubuntu!\n";
    Result:
    Code:
    [{bulldog}~]$./name.pl
    Hi, What is your name? bULlDoG
    Hello Bulldog, Welcome to Ubuntu!
    [{bulldog}~]$

  7. #7
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,712
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: "Hello Ubuntu" in every programming language

    NASM Assembly (i386)

    It could be cleaner and more optimized, I was trying to make it easy to follow.

    The command to assemble & link is at the top.

    Code:
    ; nasm helloubuntu.asm -f elf && ld helloubuntu.o -o helloubuntu
    
    section .bss
        name resb 512
    
    segment .text 
        ; Constant data:
        intro      db   "Hi! What's you're name? "
        sz_intro   equ  $-intro
        outro1     db   "Hello "
        sz_outro1  equ  $-outro1
        outro2     db   "! Welcome to Ubuntu!", 10
        sz_outro2  equ  $-outro2
        global _start
    
    ; Console in system call
    console_in:
        mov eax, 3
        mov ebx, 0
        int 0x80
    ret
    
    ; Console out system call
    console_out:
        mov eax, 4
        mov ebx, 1
        int 0x80
    ret
    
    ; Find first newline in input
    get_len:
        mov edx, 0
        get_len_loop:
            inc edx
            cmp byte [name+edx], 10
        jne get_len_loop
    ret
    
    ; Start, equivalent to C's "main"
    _start:
        mov ecx, intro
        mov edx, sz_intro
        call console_out
    
        mov ecx, name
        mov edx, 512
        call console_in
    
        mov ecx, outro1
        mov edx, sz_outro1
        call console_out
    
        mov ecx, name
        call get_len
        call console_out
    
        mov ecx, outro2
        mov edx, sz_outro2
        call console_out
    
        ; System exit call
        mov eax, 1
        int 0x80
    Last edited by Wybiral; July 10th, 2007 at 06:22 PM.

  8. #8
    Join Date
    Jul 2008
    Beans
    1,706

    Re: "Hello Ubuntu" in every programming language

    HLA (high level asm) (not checked yet due to lack of assembler but i will do it soon)

    Code:
    program hello;
    #include(stdlib.hhf);
    begin hello;
    	stdout.put("What is your name?" nl); //this is a comment, nl means new line
    	stdin.get(eax);
    	sotdout.put("Hello" eax "welcome to Ubuntu!);
    end hello;

  9. #9
    Join Date
    Jan 2007
    Location
    the third world
    Beans
    Hidden!

    Re: "Hello Ubuntu" in every programming language

    Python

    Code:
    #!/usr/bin/env python
    print "Hello, " + raw_input("Hi! What's your name? ") + "! Welcome to Ubuntu!"
    Last edited by runningwithscissors; July 10th, 2007 at 06:28 PM.
    IESVS FELLAT IN INFERNVM

  10. #10
    Join Date
    Mar 2007
    Location
    Lyngen, Norway
    Beans
    163
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: "Hello Ubuntu" in every programming language

    Quote Originally Posted by runningwithscissors View Post
    Python

    Code:
    #!/usr/bin/env python
    print "Hello, " + raw_input("Hi! What's your name? ") + "! Welcome to Ubuntu!"
    In Python 3.0:
    Code:
    print("string")
    not print "string"
    Python 3.0 is the new version in python, not released yet.(only alpha)
    IBM Thinkpad R60
    Ubuntu user: # 14440
    Please visit:
    http://www.fablab.no

Page 1 of 14 12311 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •