Write a program to print all the prime numbers from 1 to 500.
Answers
Answered by
5
Answer:
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int main ()
{
for (int i = 100; i < 500; i++)
{
bool prime = true;
if( i % 2 == 0 || i % 3 == 0 || i % 5 == 0 || i % 7 == 0 ) {
prime = false;
} else {
for (int j=9; j*j < i; j++)
{
if (i % j == 0)
{
prime = false;
break;
}
}
}
if(prime) printf("%d\n", i);
}
return 0;
}
Answered by
2
Answer:
YOUR ANSWER IS IN THE ATTACHMENT
HOPE IT HELPS....
Attachments:
Similar questions