Friday, June 17, 2016

C Language Code​: ស្វែងរកPrime Number

C Language Code 

#include<stdio.h>

int main()
{
    int number, i;
    int prime = 1;
    printf("C Program to Find Prime Number in C \n");
    printf("Enter Number : ");
    scanf("%d", &number);
    if (number <= 1)
    {
        printf("A Prime number must be a positive integer greater than 1, so %d is not a Prime number \n", number);

        printf("Press enter to continue... \n");
        fflush(stdin);
        getchar();
        return 0;
    }
    for (i = 2; i < number && prime; i++)
    {
        if (number%i == 0)
            prime = 0;
    }
    if (prime)
        printf("%d is Prime number \n", number);
    else
        printf("%d is Composite number \n", number);

    printf("Press enter to continue... \n");
    fflush(stdin);
    getchar();
    return 0;
}

Prime Number in C Output Screenshot