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

Answer Posted / roopa

#include<stdio.h>
#include <conio.h>


main()

{
int n1=0,n2=0;
printf("enter the range\n");
scanf("%d %d", &n1, &n2);
prime(n1,n2);
getch();
}

int prime(int n1, int n2)
{

int i,j;
for (i=n1;i<=n2;++i)

{
for(j=2;j<=(i/2);j++)
{
if(i%j==0)
{

break;
}
}
if(j==(i/2+1))
printf("%d\n", i);

}
}

Is This Answer Correct ?    31 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain logical errors? Compare with syntax errors.

633


shorting algorithmS

1805


which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;

2415


Write a program for Overriding.

690


How do you override a defined macro?

704






How can I read data from data files with particular formats?

607


What is function and its example?

630


How do I use strcmp?

645


Describe newline escape sequence with a sample program?

660


What does 2n 4c mean?

725


explain what is a newline escape sequence?

692


What is extern storage class in c?

515


Can a pointer be static?

628


What are the scope of static variables?

604


Explain how can I manipulate strings of multibyte characters?

787