Saturday, April 25, 2015

Prime numbers in a range given by user in C Language


#include <conio.h>

int main(int argc, char* argv[])
{
    int start = 0 , end = 0 ;
    printf("Enter the starting number in range");
    scanf_s("%d",&start);
    printf("Enter the ending number in range");
    scanf_s("%d",&end);
    for (int i = start; i < end ; i++)
    {
        int count = 0;
        for(int j = 1 ; j <= i ; j++)
        {
            if ( i % j == 0 )
            {
                count++;
                if ( count > 2)
                {
                    break;
                }
            }
        }
        if ( count <= 2 )
        {
            printf("%d\n",i);
        }
    }
    getch();
    return 0;
}

No comments:

Post a Comment

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...