How to write a code for checking Prime Number in 2023
For learning c code, students are advised to practice few basic codes, prime number checking is one of them.
In C code practice, this program logic plays a very important role. So I have designed this code as easy as possible for the students. They will be able to understand each and every step very easily.
Before going for this type of program a student should go through basics of loop structure. So that they can easily go through each step with self explanation mode.
For more code click here. For video tutorial on several topics click here.
#include <stdio.h> int main() { int p,i; printf("Enter your number : "); scanf("%d",&p); for(i=2;i<=p/2;i++) { if(p%i==0) break; } if(i>p/2) printf("This Number is Prime"); else printf("This number is Not Prime"); return 0; }