In: Electrical Engineering
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
#include<stdio.h>
void main()
{
int n,i,fact,j;
int a = 0;
printf("Enter the Number");
scanf("%d",&n);
printf("Prime Numbers are: \n");
do
{
fact=0;
for(j=1; j<=n; j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf("%d " ,i);
a=a+1
} while a<n
getch();
}