Monday, December 13, 2010

Program to display the prime numbers in the given range and show its count

#include<stdio.h>

int main()
{
    int i,j,a,b,m=0;
    printf("Enter the range:");
    scanf("%d%d",&a,&b);
    printf("The prime numbers in this range are:\n");
    for(i=a;i<=b;i++)
    {
        for(j=2;j<i;j++)
        {
            if(i%j==0)
            break;
        }
        if(j==i)
        {
        printf("%d\t",i);
        m++;
        }
    }

printf("\nThe total no.of prime numbers is %d.",m);
return 0;
}

No comments:

Post a Comment