Qqqqq
Qqqqq
Practice Program:
Solution:
if (number %% 2 == 0) {
} else {
2. Write a R program, which accepts annual basic salary of employee & calculate & displays
the income tax as per the following
Solution:
income_tax <- 0
income_tax <- 0
} else {
Solution:
if (nchar(char) != 1) {
} else {
} else {
4. Write a R program to accept any year as input & check whether the year is.
leap year or not.
Solution:
} else {
SET A
Solution:
for (i in 3:n) {
return(fib_seq)
n <- 10
fib_numbers <- fibonacci(n)
Solution:
return(sum_digits)
Solution:
} else {
Solution:
if (num <= 0) {
if (is_perfect_number(number)) {
} else {
for (i in 1:10) {
multiplication_table(number)
SET B
Solution:
if (num <= 1) {
for (i in 2:sqrt(num)) {
if (num %% i == 0) {
}
return(TRUE) # If not divisible, it is prime
if (is_prime(num)) {
primes <- c(primes, num) # Add the prime number to the vector
2. Write a R program to accept the cost price and Selling price from the key -board. Find out
if the seller has made a profit Or loss & display how much profit or loss has been made.
Solution:
} else {
cat("There is no profit or loss. The selling price is equal to the cost price.\n")
3. Accept the x and y coordinate of a point and find the quadrant in which the point lies.
Solution:
} else if (x == 0 && y != 0) {
} else if (y == 0 && x != 0) {
cat(result, "\n")
Solution:
return(TRUE)
} else {
return(FALSE)
if (is_palindrome(input_number)) {
5. Write a R program to accept a and count number of even, odd, zero digits
within that number.
Solution:
even_count <- 0
odd_count <- 0
zero_count <- 0
if (digit_num == 0) {
} else if (digit_num %% 2 == 0) {
} else {
}
input_number <- as.numeric(readline(prompt = "Enter a number: "))
SET C:
1. Use a while loop to simulate one stock price path starting at 100 and random normally
distributed percentage jumps. with mean 0 and standard deviation of 0.01 each period.
How long does it take to reach above 150 or below 50?
Solution:
time_periods <- 0
} else {
cat("The stock price fell below 50 after", time_periods, "periods.\n")