R Assignment 3
R Assignment 3
SESSION: - 2023-2025
NAME: -SHASWATI PAUL
YEAR: - 2ND
BATCH: -MCA 2C
STUDENT ID: - 231001271220
SUBJECT: - R Programming Lab
ASSIGNMENT 3
Code:-
greater_num <- function(a, b) {
if (a > b) {
return(a)
} else if (b > a) {
return(b)
} else {
return("Both numbers are equal")
}
}
greater_num(10, 20)
Output:-
# Example usage:
categorize_triangle(60, 60, 60)
Output:-
7. Categorize Triangle by Sides
Code:-
validate_triangle <- function(a, b, c) {
if (a + b > c && b + c > a && c + a > b) {
if (a == b && b == c) {
return("Equilateral")
} else if (a == b || b == c || c == a) {
return("Isosceles")
} else {
return("Scalene")
}
} else {
return("Invalid triangle")
}
}
# Example usage:
validate_triangle(3, 4, 5)
Output:-
# Example usage:
festival_bonus(40000)
Output:-
# Example usage:
calculate_bill(150)
Output:-
# Example usage:
calculate_gas_bill(5000, 5125)
Output:-
# Example usage:
income_tax(600000, 1)
# Example usage:
calculate_parking_charge(10)
Output:-
# Example usage:
calculate_notes(5370)
Output:-
return(value)
}
# Example usage:
roman_to_decimal("MCMXCIV")
Output:-
15. Determine Leap Year
Code:-
is_leap_year <- function(year) {
return(ifelse((year %% 4 == 0 & year %% 100 != 0) | (year %% 400 ==
0), TRUE, FALSE))
}
# Example usage:
is_leap_year(2024)
Output:-