C Program to print prime number
C program to print prime number is very simple and easy to write, only need to check number is divisible by 1 or number itself if yes that number is a prime number, otherwise not a prime number.
In the below code, I will print prime number up to 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,hitesh=1;
clrscr();
textcolor(2);
cprintf("PRIME NUMBER UP TO 100\n");
for(i=2;i<=100;i++)
{
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
hitesh=0;
break;
}
else
hitesh=1;
}
if(hitesh==1)
printf("%d\n",i);
}
getch();
}
No comments:
Post a Comment