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
Why static variable is used in c?
What are the types of c language?
What is the general form of a C program?
Is c a great language, or what?
When was c language developed?
How arrays can be passed to a user defined function
Process by which one bit pattern in to another by bit wise operation is?
What is difference between union All statement and Union?
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
Why pointers are used?
What is external variable in c?
Is it possible to use curly brackets ({}) to enclose single line code in c program?
What is the difference between new and malloc functions?
Is fortran still used in 2018?
Is null valid for pointers to functions?