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
What are structure members?
How can I change their mode to binary?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Write a program to print fibonacci series using recursion?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
How can this be legal c?
how could explain about job profile
ATM machine and railway reservation class/object diagram
Is javascript based on c?
Are local variables initialized to zero by default in c?
What is the correct code to have following output in c using nested for loop?
How to declare a variable?
Where are the auto variables stored?
What is the use of sizeof () in c?
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)