pgm1.R number <-c(2,3,4,5,6,7,8) addcount<-0 EvenCount<-0 if(length(number)>0) { for(num in number) { if(num%%2==0) { EvenCount <-EvenCount++1 }else{ addcount<-addcount+1 } } print(paste("total even number in vector is",EvenCount)) print(paste("addnumber in vector is",addcount)) } pgm2.R { for(i in 1:10) { print(paste("i=",i)) if(i==5) stop("iteration stopped(on.condition)at i=5") } } pgm3.R factorial<-function(n) { if(n<=1) return(1) else return(n*factorial(n-1)) } num<-5 fact<-factorial(num) cat("factorial of",num,"!is",fact) pgm12.R marks<-c(97,78,57,78,97,66,87,64,87,78,87) min<-mean(marks) med<-median(marks) mode<-function() { return(names(sort(-table(marks)))[1]) } mod<-mode() paste("mean=",min) paste("median=",med) paste("mode=",mod) pgm8.R output_file_path<-"D:\\out.txt" data<-"hello this is test" paste("written successfully",writeLines(data,output_file_path)) paste("reding a file=",readLines("D:\\out.txt"))