easy
0 views

Print "Hello world" in different languages

Create a program that prints 'Hello World' in multiple programming languages

Understand the Problem

Problem Statement

Write a program that demonstrates how to print "Hello World" in different programming languages. The program should output the "Hello World" statement for each language listed below, formatted as code examples.

The output should show the exact syntax required to print "Hello World" in each language.

Constraints

  • Program must output code examples for all listed programming languages
  • Each language example should be clearly labeled
  • Output should be formatted as code blocks
  • No input is required from user
  • Program should run without errors

Examples

Example 1
Input
Output
C:
printf("Hello World");

C++:
cout << "Hello World";

Python:
print("Hello World")

Java:
System.out.println("Hello World");

JavaScript:
console.log("Hello World!");
Explanation

This output demonstrates the exact syntax required to print "Hello World" in five different programming languages. Each language has its own way of outputting text to the console.

Solution

#include <stdio.h>

int main() {
    printf("C:\n");
    printf("printf(\"Hello World\");\n\n");
    
    printf("C++:\n");
    printf("cout << \"Hello World\";\n\n");
    
    printf("Python:\n");
    printf("print(\"Hello World\")\n\n");
    
    printf("Java:\n");
    printf("System.out.println(\"Hello World\");\n\n");
    
    printf("JavaScript:\n");
    printf("console.log(\"Hello World!\");\n\n");
    
    printf("PHP:\n");
    printf("<?php echo \"Hello World\";\n\n");
    
    printf("Ruby:\n");
    printf("puts 'Hello World'\n\n");
    
    printf("Go:\n");
    printf("package main\n");
    printf("import \"fmt\"\n");
    printf("func main() {\n");
    printf("    fmt.Println(\"Hello World\")\n");
    printf("}\n\n");
    
    printf("Kotlin:\n");
    printf("fun main() {\n");
    printf("    println(\"Hello World\")\n");
    printf("}\n");
    
    return 0;
}
Time:O(1)
Space:O(1)
Approach:

The C solution demonstrates how to print "Hello World" examples for multiple languages using the printf function. The program:

  1. Uses #include <stdio.h> to include the standard input/output library
  2. Defines the main() function as the entry point
  3. For each programming language, prints a heading followed by the corresponding "Hello World" syntax
  4. Uses escape sequences like \" to properly display quotes in the output
  5. Returns 0 to indicate successful execution

The output shows the exact code needed to print "Hello World" in each language, formatted as a demonstration program.

Visual Explanation

Loading diagram...