> Basically I can't understand the flow of algorithm ,
Well it is pretty tough, when your indentation is poor, and you're lazy with the use of braces.
For example, this should have 3 separate indent levels, not zero.
Code:
for(; i<2; i++)
if(x)
y=0; //
This is your original code, indented.
Code:
#include<stdio.h>
int main()
{
int primes[4];
int counter = 1;
int start = 3;
int prime;
int i;
primes[0] = 2;
printf("2");
while (counter < 4) {
prime = 1;
for (i = 0; i < counter && prime; i++)
if (!(start % primes[i]))
prime = 0; // here is my problem
if (prime) // How if works ???? prime = 0
{
printf("\n%d", start);
primes[counter++] = start;
}
start++;
}
printf("\n");
return 0;
}
Notice that I changed the position of the not operator if (!(start % primes[i])). Again, this would have been so much clearer expressed as if ( start % primes[i] == 0 ).
Now this is your code, with braces in all the places you left them out.
This is I guess what vikasvijayan tried to do, but made a mess of it.
Code:
#include<stdio.h>
int main()
{
int primes[4];
int counter = 1;
int start = 3;
int prime;
int i;
primes[0] = 2;
printf("2");
while (counter < 4)
{
prime = 1;
for (i = 0; i < counter && prime; i++)
{
if (!(start % primes[i]))
{
prime = 0; // here is my problem
}
}
if (prime) // How if works ???? prime = 0
{
printf("\n%d", start);
primes[counter++] = start;
}
start++;
}
printf("\n");
return 0;
}
> // How if works ???? prime = 0
if ( prime ) is merely short-hand for if ( prime != 0 )