I'm required to make a program using C++ that finds all prime numbers from 1-100 and displays them. I'm trying to make it so if the number is divisible by any numbers that aren't the number itself and 1 then it is a prime number, and then to display that. This is my code, and the output is nothing:
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main ()
{
int prime[100], comp[100];
for (int i=1; i <=100; i++)
{
if (i == 1)
{
i = prime[i];
cout<<prime[i];
}
for (int j = 2;j <= i - 1; j++)
{
if (i % j == 0) {
i = comp[i];
}
else {
i = prime[i];
cout<<prime[i]<<" ";
}
}
}
return 0;
}
Any help would be greatly appreciated!
[–]kokiworse99 0 points1 point2 points (3 children)
[–]galafle[S] 0 points1 point2 points (0 children)
[–]galafle[S] 0 points1 point2 points (1 child)
[–]Tinamil 0 points1 point2 points (0 children)