Printing Prime Numbers from 1 to 300.
Code:
#include<stdio.h>
main()
{
int number, i;
for (number=2;number<=300;number++)
{
for (i=2; i < number ; i++)
{
if (number%i==0)
break;
else
printf("\n%d", number);
}
continue;
}
}
Trying to print the first 300 Prime Numbers.
Here's the program that I made..
Now for some reason unknown to me..it is not giving out the desired output..
Can anybody point out the mistake?
i wrote a program like this in c++
didnt have time to port it over to c but should still be readable
Code:
#include <iostream> //header file
#include <cmath> //header file
using namespace std;
int main()
{
int x;
int i;
int prime;
for(x=1; x<=10000; x=x+2)
{
prime=1; //sets prime
for(i=2; i<=sqrt(x); i++)
{
if(x % i == 0)
{
prime = 0;
i=sqrt(x)+1;
}
}
if(prime == 1)
{
cout << x << " is prime.\n"; //"cout" equal to the "printf" command in c
}
}
return 0;
}