assigning prime number to an array problem

I want to assign prime number to the element of an array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stdafx.h"
#include <iostream>
#include <conio.h>                //For Console Input/Output function like clrscr & getche
using namespace std;           //Using the "standard" namespace of iostream class
void main()
{
                                //For Clearing the console screen
int i,j,n,flag, A[10];
cout<<"Enter max. limit:";
cin>>n;                                //User enters the value of 'n'
for(i=2;i<=n;i++)                //Counting starts from '2' as '1' is not a prime number
{
flag=0;                                 //Initializing the Flag variable inside the first for loop, in order to check  for(j=2;j<i;j++)                  //for prime number 
{ for (j = 2; j<i ; j++)
if(i%j==0)                          //Checking for the condition that if, 'i' is fully divided by 'j'
flag++;                                //If 'i' is fully divided by 'j' then increment the value of 'flag'
}
if(flag==0)                          //Checking for the condition in which the value of flag is still zero
{ for (int w = 0; w<10; w++)
{A[w] = i; cout<<A[w];}}
}
getche();                             //To exit the program after an user's keystroke
}
Last edited on
A quick tip - no one's going to read this unless you put your code here using code brackets
Sane indentation would be nice too.

You do already some prime-like operations and you do assign something to an array.

Why do you print every prime ten times?
Topic archived. No new replies allowed.