This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hcf <- function(x, y) { | |
if(x > y) { | |
smaller = y | |
} else { | |
smaller = x | |
} | |
for(i in 1:smaller) { | |
if((x %% i == 0) && (y %% i == 0)) { | |
hcf = i | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nterms = as.integer(readline(prompt="How many terms should I print? ")) | |
n1 = 0 | |
n2 = 1 | |
count = 2 | |
if(nterms <= 0) { | |
print("Plese enter a positive integer") | |
} else { | |
if(nterms == 1) { | |
print("Fibonacci sequence:") | |
print(n1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
year = as.integer(readline(prompt="Enter a year: ")) | |
if((year %% 4) == 0) { | |
if((year %% 100) == 0) { | |
if((year %% 400) == 0) { | |
print(paste(year,"is a leap year")) | |
} else { | |
print(paste(year,"is not a leap year")) | |
} | |
} else { | |
print(paste(year,"is a leap year")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recur_factorial <- function(n) { | |
if(n <= 1) { | |
return(1) | |
} else { | |
return(n * recur_factorial(n-1)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
convert_to_binary <- function(n) { | |
if(n > 1) { | |
convert_to_binary(as.integer(n/2)) | |
} | |
cat(n %% 2) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max.temp <- c(22, 27, 26, 24, 23, 26, 28) | |
barplot(max.temp, | |
main = "Maximum Temperatures in a Week", | |
xlab = "Degrees Celsius", | |
ylab = "Day", | |
names.arg = c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), | |
col = "red", | |
horiz = TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
import math | |
import random | |
screen = turtle.Screen() | |
screen.setup(700,600) | |
screen.title("Testing Mountain Curves") | |
turtle.hideturtle() | |
turtle.speed(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear | |
read -p "May I know your name, please? " name | |
echo "Hello $name, let us be friends!" | |
echo "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "What is the name of your file?" | |
read FILE | |
echo "This file will be created as ${FILE}_file." | |
touch ${FILE}_file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plotrix) | |
x <- c(21, 62, 10,53) | |
lbl <- c("USA","China","Indonesia","India") | |
pie3D(x,labels = lbl,explode = 0.1, main = "Pie Chart of Most Populous Countries ") |