Computer Science, asked by harshitdehariya422, 1 month ago

Write a program which takes input as an array of numbers between 2 to 99, and print only those numbers which are prime and at the prime index. For example if input array is [4,5,2,8,9, 19,6, 12], it should print 2 - at index 2, 19 - at index 5. If array contains number outside 2-99 it should say invalid input.

Answers

Answered by adheksumantakumar75
0

Answer:

java = System.out.println("4,5,2,8,9, 19,6, 12")

Explanation:

Answered by VaibhavGoel0
0

Answer:

let a=2, b=99, i, j, flag,k=0,flag2,l;

   console.log("Numbers which are prime and at the prime index between " + a + " and " + b + " are: ");

   for (i = a; i <= b; i++)

   {

       if (i == 1 || i == 0 )

           continue;

       flag = 1;

       flag2 = 1;

       

       for (j = 2; j <= i / 2; ++j)

       {

           if (i % j == 0)

           {

               flag = 0;

               break;

           }

       }

       if (flag == 1 && k!=0 && k!= 1)

       {

         for (l = 2; l <= k / 2; ++l)

         {

           if (k % l == 0)

           {

               flag2 = 0;

               break;

           }

         }

         

         if(flag2 == 1)

         {

           console.log(i,"- at index ",k);

         }

       }

       k++;

   }

Explanation:

First Condition : Prime numbers from 2-99 needs to be printed.

Second condition : Only those Prime numbers whose index are also Prime...

Hence the output is...

OUTPUT:

5 - at index  3

7 - at index  5

13 - at index  11

19 - at index  17

31 - at index  29

43 - at index  41

61 - at index  59

73 - at index  71

Similar questions