Math and Number Utilities in R

Practice factorials, prime checks, Armstrong numbers, Fibonacci, leap year logic, GCD/LCM, sums, and tables. Emphasis on clear numeric utilities.

R Program to check Armstrong Number

Program (R)
Example & Expected Output

Checks if a number equals sum of cubes of its digits.

[1] TRUE

R Program to Find the Factorial of a Number

Program (R)
Example & Expected Output

Computes factorial using a for loop.

[1] 120

R Multiplication Table

Program (R)
Example & Expected Output

Prints a multiplication table for a given number.

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

R Program to Check Prime Number

Program (R)
Example & Expected Output

Checks primality with trial division.

[1] TRUE

R Program to Print the Fibonacci Sequence

Program (R)
Example & Expected Output

Generates Fibonacci numbers iteratively.

[1] 0 1 1 2 3 5 8 13 21 34

R Program to Check for Leap Year

Program (R)
Example & Expected Output

Checks leap year using standard rules.

[1] TRUE

R program to Find the Factorial of a Number Using Recursion

Program (R)
Example & Expected Output

Computes factorial recursively.

[1] 120

Fibonacci Sequence Using Recursion in R

Program (R)
Example & Expected Output

Generates first N Fibonacci numbers using recursion.

[1] 0 1 1 2 3 5 8 13 21 34

R Program to Find H.C.F. or G.C.D.

Program (R)
Example & Expected Output

Finds greatest common divisor via Euclidean algorithm.

[1] 12

R Program to Find L.C.M.

Program (R)
Example & Expected Output

Computes least common multiple using GCD.

[1] 36

R Program to Concatenate Two Strings

Program (R)
Example & Expected Output

Concatenates strings using paste0.

[1] "Hello World"

Frequently Asked Questions

Install R (from CRAN). Save the code in a file like main.R, then run Rscript main.R from your terminal. Alternatively, use an IDE such as RStudio.

No. All examples rely on base R functions to ensure compatibility across systems. Where packages are useful, they’ll be explicitly mentioned.

Yes. Copy the code, tweak inputs, and observe outputs. Experimentation is the fastest way to build intuition and mastery.

Yes. R is cross-platform. The examples run on Windows, macOS, and Linux with a standard R installation.

Learn R the Practical Way

R is a powerful language for data analysis, visualization, and statistical computing. Practicing small, focused programs builds fluency with vectors, data frames, lists, functions, control flow, and string manipulation.

On this page, you’ll find clean, well-formatted examples that run across platforms. Each example includes a short description and expected output so you can quickly verify your understanding. Explore the topics via the sidebar and extend the code to experiment further.

Whether you’re preparing for coursework, handling data tasks at work, or learning R for research, these examples offer a practical path to mastery. Bookmark the page and revisit to keep sharpening your skills.