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

What is double pointer in c?

599


What is the size of a union variable?

608


What are pointers? What are stacks and queues?

589


When is a “switch” statement preferable over an “if” statement?

657


Do string constants represent numerical values?

936






Compare array data type to pointer data type

607


What are the differences between Structures and Arrays?

618


What kind of structure is a house?

568


I need testPalindrome and removeSpace #include #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }

2222


How can I access an I o board directly?

634


What is the difference between null pointer and wild pointer?

648


Why doesnt that code work?

610


What is the use of getch ()?

648


Which is better pointer or array?

614


What is array in c with example?

627