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


Please Help Members By Posting Answers For Below Questions

Why static variable is used in c?

530


What are the types of c language?

531


What is the general form of a C program?

575


Is c a great language, or what?

578


When was c language developed?

670






How arrays can be passed to a user defined function

553


Process by which one bit pattern in to another by bit wise operation is?

593


What is difference between union All statement and Union?

606


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.

630


Why pointers are used?

602


What is external variable in c?

583


Is it possible to use curly brackets ({}) to enclose single line code in c program?

761


What is the difference between new and malloc functions?

544


Is fortran still used in 2018?

564


Is null valid for pointers to functions?

587