List all the Prime Numbers

#include<stdio.h>
void main()
{
int n,i,j,flag;
printf("\n\nEnter the limit\t:");
scanf("%d",&n);
printf("\nThe prime numbers within the given limit:\n");
for(i=1;i<=n;i++)
{
flag=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d\t",i);
}
}

   

Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C