Write a program to print all the prime numbers with in the
given range

Answer Posted / pooja mishra

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int range,c;
cout<<"enter the range";
cin>>range;
for(int i=1;i<=range;i++)
{
c=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
c++;
}
if(c==o)
cout<<i<<"\n";
}
getch();
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which one would you prefer - a macro or a function?

604


Explain how can I avoid the abort, retry, fail messages?

591


What is c variable?

552


How do you override a defined macro?

699


Explain what are the different file extensions involved when programming in c?

633






How can variables be characterized?

1652


Why are algorithms important in c program?

620


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3691


Give basis knowledge of web designing ...

1574


Write a program to print fibonacci series without using recursion?

610


How can I convert a number to a string?

608


If fflush wont work, what can I use to flush input?

615


What does dm mean sexually?

814


Lists the benefits of c programming language?

598


Explain how do you view the path?

655