# Printing a prime normalized sequence

The program below generates a prime normalised sequence. So, what happens is this:

It asks you to provide a number within a range. Program then calculates a factor which is inverse of product of all the prime numbers till the first prime number larger than the number you provided.

It then divides each number from 1 till the number you provided with the factor. This is prime normalised sequence till the number you provided. The prime numbers are statically provided and hence can be increased in number.

We are choosing to print only 30 elements of the sequence. The code below, however, allows you to print more easily.

/*p[] is an extern const int array already initialised out of main */
int main()
{
int COUNT = 0;
int PRIME = 0, i;
int m;
long double fact = 1.0;
long double p_nor[100];   /* declaring array which holds output */

puts("Enter the number between 2 and 10000.\n");
scanf("%d", &COUNT);        /* store the provided value in c */

if( (COUNT < 10000) && (COUNT > 2) )
{
i = 0;
while(COUNT > p[i])           /* traversing p_10k till COUNT */
{
i += 1;
}
printf("%d prime numbers are below.\n", i);
PRIME = i;

while(0 < i)                            /* finding the factor */
{
fact /= (p[i]);
i -= 1;
}
printf("%LE is the factor.\n", fact);
}
else
printf("Is %d 'between' 2 and 100? Are you dumb!\n", COUNT);
return 0;

printf("The %d lies between %d and %d.\n", COUNT, p[PRIME -1],p[PRIME]);

for(i = 0; i < 29; ++i )
{
p_nor[i] = ( (long double)COUNT * fact );
printf("%LE\n", p_nor[i]);
COUNT -= 1;
if(0 > COUNT)
{
printf("%LE is the normalised count.\n", p_nor[COUNT]);
return 0;
}
}

printf("%LE is the normalised count.\n", p_nor[COUNT]);

return 0;
}

• Does this code work? What does this code do? Please add some more information. – Simon Forsberg May 5 '16 at 13:35
• Proper indentation would help make this code more readable. – FredK May 5 '16 at 15:50
• printf("Is %d 'between' 2 and 100? Are you dumb!\n", COUNT); Insulting the user is extremely non-professional. – FredK May 5 '16 at 15:52
• I wasn't allowed more than four spaces of indentation. – Abhineet Sharma May 8 '16 at 4:25
• @AbhineetSharma If you get called "dumb" when you get the ticket, it is still insulting. Just think of ordinary applications you use, how many times have you seen them calling the user (you) dumb? – Simon Forsberg May 8 '16 at 10:39

Major

1. Missing #include <stdio.h>

2. p not declared. Use extern rather than comment.

extern const int p[];

3. All the code after return 0; is not used. Confident code is missing {} around printf("Is %d 'between' 2 and 100? Are you dumb!\n", COUNT); return 0; and it therefore non-correctly functional.

else
printf("Is %d 'between' 2 and 100? Are you dumb!\n", COUNT);
return 0;

printf("The %d lies between %d and %d.\n", COUNT, p[PRIME - 1], p[PRIME]);
for (i = 0; i < 29; ++i) {

4. I would expect inclusiveness given the prompt ""Enter the number between 2 and 10000"

puts("Enter the number between 2 and 10000.\n");
scanf("%d", &COUNT); /* store the provided value in c */

// if ((COUNT < 10000) && (COUNT > 2)) {
if ((COUNT <= 10000) && (COUNT >= 2)) {

5. Unclear why 100 rather than 29 for long double p_nor[100]; ... for (i = 0; i < 29; ++i) { p_nor[i] = .... Further p_nor[COUNT] looks like it could easily be out of range.

Minor

1. int m; unused.

2. Single space indenting is not that useful. Also consider the following 2 snippets. They certainly are incorrectly indented.

else
printf("Is %d 'between' 2 and 100? Are you dumb!\n", COUNT);
return 0;

if( (COUNT < 10000) && (COUNT > 2) )
{
i = 0;
while(COUNT > p[i])

3. All uppercase variables names like COUNT, PRIME will often be reviewed by coders as being macro constants. Better to use Count or count, etc.

• you should check the codepad link I attached, it has lesser typos. I have several versions of this code where names keep changing and what not. – Abhineet Sharma May 11 '16 at 3:00
• codepad.org/ej9Wq0e0 – Abhineet Sharma May 11 '16 at 3:01
• @Abhineet Sharma Post your code at this site instead. – chux May 11 '16 at 3:14