Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
#include<stdio.h>
#include<conio.h>
int main()
    {
    clrscr();
    int i=3,j=2,num,rem;
    printf("enter the number less than which you need all the prime numbers:");
    scanf("d",&num);
    while(i<=num)
        {
        j=2;
        while(j<=i-1)
            {
            rem=(i%j);
            if(rem==0)
                {
                break;
                }
            j++;
            }
        if(j==i)
            printf("%d\n",i);
        i++;
        }
    getch();
    return 0;
    }


[edit]Indentation added - OriginalGriff[/edit]
Posted
Updated 20-Dec-14 0:05am
v2
Comments
Member 11324568 20-Dec-14 5:47am    
there is no error...but when i run my programme...instead of listing out the prime numbers i get a blank..i didnt find any mistake..please help me out..thanks
Afzaal Ahmad Zeeshan 20-Dec-14 6:00am    
Add this piece of information to the question body and not in the comments.
Member 11324568 20-Dec-14 6:09am    
ok,sorry but please tell me what the error is,i compiled this programme in an online compiler and it was displaying prime numbers never ending ,it has crossed 9 digit figure already and its still running..i want to run it in turboc and its failing..plase afzaal try to point out the mistake.

1 solution

You need to start with looking at the basics.
C#
int i=3,j=2,num,rem;
printf("enter the number less than which you need all the prime numbers:");
scanf("d",&num);

If you look at the definition of scanf: http://www.cplusplus.com/reference/cstdio/scanf/[^] you will see that "d" is not a vlaid format specifier: it should be "%d":
C#
int i=3,j=2,num,rem;
printf("enter the number less than which you need all the prime numbers:");
scanf("%d",&num);

Now you will get into the loop.
 
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