easy
0 views

Multiply by 2

Read an integer from input and output the result of multiplying it by 2

Understand the Problem

Problem Statement

The program must accept a number and multiply it by 2.

Constraints

  • Input must be a single integer value
  • The integer must be within standard integer range for the programming language
  • Output must be exactly twice the input value
  • Program should read from standard input and write to standard output

Examples

Example 1
Input
10
Output
20
Explanation

When the input is 10, multiplying by 2 gives 10 × 2 = 20, which is the expected output.

Example 2
Input
50
Output
100
Explanation

When the input is 50, multiplying by 2 gives 50 × 2 = 100, which is the expected output.

Solution

#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);
    printf("%d", N * 2);
    return 0;
}
Time:O(1)
Space:O(1)
Approach:

The C solution:

  1. Includes stdio.h for input/output functions
  2. Declares an integer variable N to store the input
  3. Uses scanf to read an integer from standard input
  4. Multiplies N by 2 and prints the result using printf
  5. Returns 0 to indicate successful execution

The code uses standard C input/output functions and performs the multiplication in a single operation.

Visual Explanation

Loading diagram...