Program to read input from keyboard

Program to read input from keyboard

  • Write a program to read input from keyboard in C
  • Write a program to read input from keyboard in C++
  • Write a program to read input from keyboard in Python
  • Write a program to read input from keyboard in PHP
  • Write a program to read input from keyboard in Java
  • Write a program to read input from keyboard in Java Script
  • Write a program to read input from keyboard in C#

Explanation:

In order to read input from the keyboard, one must first accept user input and then store it in a variable. Depending on the programming language, the approach changes.

Program to read input from keyboard

#include <stdio.h>

int main() {
    char input[100];
    printf("Enter something: ");
    fgets(input, 100, stdin);
    printf("You entered: %s", input);
    return 0;
}

#include <iostream>
#include <string>

int main() {
    std::string input;
    std::cout << "Enter something: ";
    std::getline(std::cin, input);
    std::cout << "You entered: " << input << std::endl;
    return 0;
}

input_data = input("Enter something: ")
print(f"You entered: {input_data}")

<?php
echo "Enter something: ";
$input = trim(fgets(STDIN));
echo "You entered: $input\n";
?>

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter something: ");
        String input = scanner.nextLine();
        System.out.println("You entered: " + input);
    }
}

let input = prompt("Enter something: ");
console.log(`You entered: ${input}`);

using System;

class Program {
    static void Main() {
        Console.Write("Enter something: ");
        string input = Console.ReadLine();
        Console.WriteLine($"You entered: {input}");
    }
}

List of All Programs