Code Scrappers


Prime number Pyramid pattern C program


              #include<stdio.h>
              #include<stdlib.h>

              int prime(int n);

              void main()
              {
                  int i, j;

                  int n = 2;

                 for (i = 0; i < 7; i++)
                 {
                      printf("\n");

                      for (j = 0; j <= i; j++)
                      {
                          while(!prime(n))
                          {
                              n++;
                          }

                          printf("%d\t", n++);
                      }
                 }
              }

              int prime(int n)
              {
                  int i, count;

                  for (i = 2; i < n; i++)
                  {
                        if (n % i != 0)

                        count = 1;

                        else
                        {
                            count = 0;

                            break;
                        }
                 }

                 if (count == 1 || n == 2)

                    return (1);

                 else

                    return (0);
              }



          



Output

      2
      3       5
      7       11      13
      17      19      23      29
      31      37      41      43      47