Q:

Write a C Program to Print Prime number Pyramid

0

Write a C Program to Print Prime number Pyramid. Here’s simple C Program to Print Prime number Pyramid using For loop in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Here is source code of the C Program to Print Prime number Pyramid using For loop. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.

 
 

SOURCE CODE : :

/*  C Program to Print Prime number Pyramid using For loop  */

#include<stdio.h>

int prime(int num);
int main() {
   int i, j;
   int num = 2;

   for (i = 0; i < 5; i++) {
      printf("\n");
      for (j = 0; j <= i; j++) {
         while (!prime(num)) {
            num++;
         }
         printf("%d  ", num++);
      }
   }
   return (0);
}

int prime(int num) {
   int i, flag;
   for (i = 2; i < num; i++) {
      if (num % i != 0)
         flag = 1;
      else {
         flag = 0;
         break;
      }
   }

   if (flag == 1 || num == 2)
      return (1);
   else
      return (0);
}

Output : :


/*  C Program to Print Prime numbers Pyramid using For loop  */

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

Process returned 0

Above is the source code for C Program to Print Prime numbers Pyramid using For loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

7 Number Pattern Programs in C Programming... >>
<< Write a C Program to Print Number Pyramid using Fo...