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 / vadivelt
Hi.
Have a look on the code i hav written below.
Just give max no(in this question 500) as a input, u ll get
the prime nos in this range.
#include<stdio.h>
#include<conio.h>
main()
{
int n, j, k, flag = 0;
printf("ENTER THE NO\n");
scanf("%d", &n);
printf("\nPRIME NOS IN THIS RANGE\n");
for(j = 1; j<= n; j++)
{
for(k = j; k>=1; k--)
{
if(j%k == 0)
flag++;
}
if(flag == 2)
{
printf("%d ", j);
}
flag = 0;
}
getch();
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
Where can I get an ansi-compatible lint?
An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above
The file stdio.h, what does it contain?
Why do we use int main instead of void main in c?
When is a void pointer used?
Why we use break in c?
What is %d used for?
Create a simple code fragment that will swap the values of two variables num1 and num2.
What is file in c preprocessor?
Is c easy to learn?
What are two dimensional arrays alternatively called as?
What does malloc () calloc () realloc () free () do?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
Explain how do you sort filenames in a directory?
What is keyword with example?