Algorithm
Step 1: Start
Step 2: Declare integer variables n, i, count
Step 3: Take input for number (n)
Step 4: Initialize count = 0
Step 5: Loop from 1 to n and check divisibility
Step 6: If count == 2, print "Prime" else print "Not Prime"
Step 7: End
Flowchart
graph TD;
A([Start]) --> B[/Input n/];
B --> C[Initialize count = 0];
C --> D[Loop i = 1 to n];
D --> E{n % i == 0};
E -->|Yes| F[Increment count];
E -->|No| D;
F --> D;
D --> G{count == 2};
G -->|Yes| H[/"Prime Number"/];
G -->|No| I[/"Not a Prime Number"/];
H --> J([End]);
I --> J;
%% Define styles
classDef start fill:#00cc44,stroke:#006622,stroke-width:2px,color:#ffffff;
classDef stop fill:#ff4444,stroke:#cc0000,stroke-width:2px,color:#ffffff;
classDef input_output fill:#ffdd44,stroke:#cc9900,stroke-width:2px,color:#000000;
classDef process fill:#4488ff,stroke:#0044cc,stroke-width:2px,color:#ffffff;
classDef decision fill:#ff8844,stroke:#cc4400,stroke-width:2px,color:#ffffff;
%% Apply styles
class A start;
class J stop;
class B,H,I input_output;
class C,D,F process;
class E,G decision;
Program
<stdio.h>
int main()
{
int n, i, r, count = 0;
printf("Enter a Number:");
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
r = n % i;
if(r == 0)
{
count++;
}
}
if(count == 2)
{
printf("\n%d is a Prime Number", n);
}
else
{
printf("\n%d is Not a Prime Number", n);
}
return 0;
}
Test Cases
Input: 7
Output: 7 is a Prime Number
Input: 10
Output: 10 is Not a Prime Number