C Online Compiler
Example: Prime and Composite Numbers C Program
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Prime and Composite Numbers C Program #include <stdio.h> int main() { int x, i = 2, f = 0; // x - Value of the input integer number printf("-----Enter the positive integer number-----\n"); scanf("%d", &x); if (x == 1) { printf("1 is neither the prime nor the composite number!\n"); } else { while (i <= x / 2) { // This is the condition for non-prime if (x % i == 0) { f = 1; break; } ++i; } if (f == 0) { printf("\n%d is the prime number.\n", x); } else { printf("\n%d is not the prime number.\n", x); } } return 0; }
23
Output
Clear
ADVERTISEMENTS