C Programming Code Examples C > Pyramid Patterns Code Examples Program to Print prime number Pyramid Program to Print prime number Pyramid Prime Numbers : Numbers that are divisible by 1 and number itself is called Prime number. This program is nothing but the pyramid of the prime numbers . To Evaluate Number is Prime or not Consecutively divide that number from 2 to n/2 Example : to find whether 17 is prime or not divide that number from 2 to (17/2 = 8) if none of the remainder is zero then the number is surely prime else number is non-prime. Remaining Logic is same as Any other Nested Pyramid #include<stdio.h> int prime(int num); int main() { int x, y; int num = 2; for (x = 0; x < 5; x++) { printf("\n"); for (y = 0; y <= x; y++) { while (!prime(num)) { num++; } printf("%d\t", num++); } } return (0); } int prime(int num) { int x, flag; for (x = 2; x < num; x++) { if (num % x != 0) flag = 1; else { flag = 0; break; } } if (flag == 1 || num == 2) return (1); else return (0); }