Click the Twitter icon to follow our tweets and
know more about us.

Triangle of prime numbers till n

class Triangle
{
 public static void main(int n)
 {
  int i,j,c,l,k=0;
  for(i=1;i<=n;i++)
  {
     c=0;
     for(j=1;j<=i;j++)
     if(i%j==0)
     c++;
  if(c==2)
                {
     k++;
     for(l=1;l<=k;l++)
     System.out.print(i+" ");
     System.out.println();
   }
  }

}
------------------OUTPUT---------------------
Input-:13
2
3 3
5 5 5
7 7 7 7
11 11 11 11 11
13 13 13 13 13 13

Comments (0)

Post a Comment