write the program for prime numbers?

Answer Posted / chinnakannasabari

#include <stdio.h>


int main (void)
{
int i, nb, count, test;
test = count = 0;
printf ("enter integer: ");
if (scanf ("%d", &nb) != 1)
return -1;

for (i = 2; i < nb; i++, count++)
if (nb % i == 0)
test = 1;
if (!test)
printf ("%d prime number, number of iterations = %dn",
nb, count);
else
printf ("%d is not a prime number, number of iterations
= %dn", nb,count);
return 0;
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 4 types of functions?

818


Why static is used in c?

858


What is the use of the function in c?

819


What are actual arguments?

877


What is integer constants?

840


Explain low-order bytes.

843


What are the different types of control structures?

823


How can you invoke another program from within a C program?

847


How to delete a node from linked list w/o using collectons?

2416


What are nested functions in c?

807


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

987


Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

961


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

880


What are identifiers and keywords in c?

808


Why do we use c for the speed of light?

840