i want to asked a question about c program the question is:

create a c program that displays all prime numbers less than
500? using looping statement

Answer Posted / ashwin kumar

I hope this is right code for you
1st it promt for max number then enter 500 then you will
get result.


#include<stdio.h>
#include<conio.h>
int main()
{
int value,j,i,value2,flag=0,count=0;
clrscr();
printf("enter limit up to which prime numbers to be
printed : ");
scanf("%d",&value2);
printf("\n\n\nlist of prime numbers are:\n\n");
for(j=1;j<=value2;j++)
{
flag=0;
value=j;
for(i=2;i<value;i++)
{
if(value%i==0)
{

flag=flag+1;
goto l1;

}


}
l1:
if(!(flag==1||value==2))
{
printf("%-10d",value);
count+=1;
}
}
printf("\n\ntotal number of prime numbers between 1 and %d
are : %d",value2,count);
getch();
return 0;

}



if their is any changes required or any suggestions mail
me at molugu.ashwin@gmail.com

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

596


What is the auto keyword good for?

610


What’s a signal? Explain what do I use signals for?

590


Give differences between - new and malloc() , delete and free() ?

596


What is the scope of an external variable in c?

556






main() { printf("hello"); fork(); }

679


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1119


What are the similarities between c and c++?

585


What is volatile keyword in c?

569


What is the size of array float a(10)?

642


What's the difference between constant char *p and char * constant p?

646


Is the exit() function same as the return statement? Explain.

650


What is a stream water?

638


What are the different types of endless loops?

606


How can you invoke another program from within a C program?

607