Hey there, need some assistance. I want to print out prime numbers from 1 to 100. I've created a program but the output is this.
5
7
11
13
17
19
23
25
29
31
35
37
41
43
47
49
53
55
59
61
65
67
71
73
77
79
83
85
89
91
95
97
here is the source code: Im using DEV C++
#include<stdio.h>
#include<conio.h>
main()
{
int num1;
for(num1=2;num1<=97;num1++)
{
if((num1%2!=0)&&(num1%3!=0))
printf("\n%d",num1);
}
Yes, what you are using is called the "Sieve of Eratosthenes", but you are only sieving multiples of 3 and 5. You must also sieve multiples of all other prime numbers < sqrt(100).
#include <iostream>
using namespace std;
#include <process.h>
int main()
{
unsigned long n,j;
cout<<"enter a number:";
cin>>n;
for(j=2;j<=n/2;j++)
if (n%j ==0)
{
cout<<"its not a prime:";
exit(0);
}
cout<<"its a prime";
cout<<endl;
return 0;
}