Big_Data_Slip_12

Slip No.12

1) Write an R Program to calculate Multiplication Table.

1. Open RStudio.

2. Create a New Script:
Go to File > New File > R Script, or press Ctrl + Shift + N (Windows).

3. Type these code in the Script:

    # Function to generate a multiplication table for a given number
    generate_multiplication_table <- function(number, range = 10) {
    cat("Multiplication Table for", number, "\n")
    for (i in 1:range) {
    cat(number, "x", i, "=", number * i, "\n")
    }
    }

    # Example usage
    number <- 5 # Change this number to generate a different multiplication table
    generate_multiplication_table(number)

4. Save the Script:
Save the script by going to File > Save, or press Ctrl + S (Windows). Name the file something like multiplication_table.R.

5. Run the Script:
You can run the script by clicking the Source button at the top of the script editor, or by selecting the entire script and pressing Ctrl + Enter (Windows).

No comments:

Post a Comment