Click here to Skip to main content
15,446,510 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this code is for a program that prints the prime numbers between two specific us and characters must be printed , my does not print character ,

What I have tried:

#include <stdio.h>;

int main()
    int i, j, start, end;
    int isPrime;
    scanf("%d", &start);
    scanf("%d", &end);

    if(start < 2) 
        start = 2;
    for(i=start; i<=end; i++)
        isPrime = 1; 
        for(j=2; j<=i/2; j++)
                isPrime = 0;
        if(isPrime==1 )
            printf("%d,", i);

    return 0;
Updated 25-Apr-21 4:30am
Patrice T 25-Apr-21 8:38am     CRLF
In html, '<' have a special meaning and need to be encoded to avoid problems. Use Improve question to update your question.
Richard MacCutchan 25-Apr-21 8:49am     CRLF
When I run your code I get the following result:
What is the problem? Also, please edit your question to remove those spurious characters.

How to print a character , between output numbers

Can you give more details ?
Because actually, your code just print a comma between primes.
Share this answer
Instead of always printing like this:
printf("%d,", i);
you need to be a little cleverer - ort you list will always end with a comma:
2, 3, 5, 7, 11, 13, 17,

So ... set a variable before the loop to zero and check it in the loop:
if (isPrime)
   if (isNotFirst)
   printf("%d", i);
   isNotFirst = 1;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900