[R] Need help in R

Anas Jamshed @n@@j@m@hed1994 @end|ng |rom gm@||@com
Tue Oct 26 22:39:23 CEST 2021


Its not homework . Basically i want to get easy solution:
I am trying this for ist problem:

n= seq(1,100)

for (j in n:100) {
      f = 1
      i = 2
      n = j
      while (i <= n / 2) {
        if (n %% i == 0) {
          f = 0
          break
        }
        i = i + 1
      }
      if (f == 1) {
        print(paste("Number is prime :", n))
      }
    }

On Wed, Oct 27, 2021 at 1:35 AM Rolf Turner <r.turner using auckland.ac.nz> wrote:

>
> On Wed, 27 Oct 2021 01:09:50 +0500
> Anas Jamshed <anasjamshed1994 using gmail.com> wrote:
>
> > I need help to these questions
> >
> > ### Question 1
> > Create a variable containing a sequence of numbers from 1 to 100:
> >
> > Iterate over the variables and print those numbers which are prime.
> >
> >
> > ### Question 2
> > Create a matrix of size 3x3 called mat_1:
> >
> >  Iterate over all the values one by one and print the element as well
> > as the position in the matrix (row, col)
>
> You really should do your own homework.
>
> cheers,
>
> Rolf Turner
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list