Pattern Programs All Patterns,Numeric Patterns Pattern 199 (Prime No.Pattern)

Pattern 199 (Prime No.Pattern)

Pattern 199 (Prime No.Pattern) post thumbnail image

C

#include <stdio.h>

int main ()
{
  int n = 5;
  int i,j,k,r;
  int cn=1,count;

  for(i = 1; i <= n; i++)
  {
    for (j = 1; j <= n; j++)
    {
      for (k = cn + 1; k <= 10000; k++)
      {
        cn=k;
        count=0;
        for (r = 1; r <= cn; r++)
        {
          if(cn%r==0)
            count++;
        }
        if(count==2)
        {
          printf("%2d ",cn );
          break;
        }

      }

    }
    printf ("\n");
  }
  return 0;
}

C++

#include <iostream.h>
#include <iomanip.h>

int main ()
{
  int n = 5;
  int r;
  int cn=1,count;
  
  for(int i = 1; i <= n; i++)
  {
    for(int j = 1; j <= n; j++)
    {
     for (int k = cn + 1; k <= 10000; k++) 
     {
       cn=k;
       count=0;
       for (r = 1; r <= cn; r++)  
       {
        if(cn%r==0)
          count++;
       }
       if(count==2)
       {
        cout<<setw(3)<<cn;
        break;
       }
      
     }
     
    }
   cout<<endl;
  }
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  int n = 5;
	  int r;
	  int cn = 1;
	  int count;

	  for (int i = 1; i <= n; i++)
	  {
		for (int j = 1; j <= n; j++)
		{
		 for (int k = cn + 1; k <= 10000; k++)
		 {
		   cn = k;
		   count = 0;
		   for (r = 1; r <= cn; r++)
		   {
			if (cn % r == 0)
			{
			  count++;
			}
		   }
		   if (count == 2)
		   {
			System.out.printf("%3d", cn);
			break;
		   }

		 }

		}
	   System.out.println();
	  }
	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 5;
    int r;
    int cn = 1;
    int count;

    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= n; j++)
      {
        for (int k = cn + 1; k <= 10000; k++)
        {
          cn = k;
          count = 0;
          for (r = 1; r <= cn; r++)
          {
            if (cn % r == 0)
            {
              count++;
            }
          }
          if (count == 2)
          {
            Console.Write("{0,3:D}", cn);
            break;
          }

        }

      }
      Console.WriteLine();
    }

    Console.ReadKey(true);
  }
}

Python

n = 5
cn = 1

for x in range(1, n + 1):
  for y in range(1, n + 1):
    for p in range(cn + 1, 10000):
      cn = p
      count = 0

      for z in range(1, cn + 1):
        if cn % z == 0:
           count += 1

      if count == 2:
         print("{:2d} ".format(cn), end="")
         break
  print()
5 2 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns