Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Where can I get an ansi-compatible lint?

1201


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

1260


The file stdio.h, what does it contain?

1214


Why do we use int main instead of void main in c?

1199


When is a void pointer used?

1308


Why we use break in c?

1072


What is %d used for?

1090


Create a simple code fragment that will swap the values of two variables num1 and num2.

1329


What is file in c preprocessor?

1194


Is c easy to learn?

1031


What are two dimensional arrays alternatively called as?

1243


What does malloc () calloc () realloc () free () do?

1103


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1644


Explain how do you sort filenames in a directory?

1075


What is keyword with example?

1123