+ 3
How can I make an array if I don't know its size or what it contains?
I'm working on a program that calculates all the prime numbers from 1 to n so i cant't know the size of the array. What should I do?
2 Réponses
+ 15
4 calculating prime no there is no need of array but u can use dynamic array
+ 2
#include<iostream>
using namespace std;
int main()
{
int n,i,j,flag;
cin>>n;
cout<<"2\n";
for(i=3;i<=n;i++)
{
for(j=2;j<=i/2;j++)
{
flag = 1;
if(i%j==0)
{ flag = 0;
break; }
}
if(flag == 1)
{ cout<<i<<"\n"; }
}
return 0;
}
*** Try this. This will give you the results. ***