Tuesday, November 28, 2017

Prime Number Checker in C

A program that I wrote using C language that will ask the user to give a number and then our program will determine if the given number in a prime number or not.  The code is very simple and easy to use.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.






Sample Program Output


Program Listing

prime.c

#include <stdio.h>

int main()
{
    int num=0, a=0, flag = 0;



    printf("Prime Number Checker in C");
    printf("\n\n");
    printf("Give a Number :  ");
    scanf("%d",&num);

    for(a=2; a<=num/2; a++)
    {

        if(num%a==0)
        {
            flag=1;
            break;
        }
    }

    if (flag==0) {
        printf("\n\n");
        printf("The number %d is a prime number.",num);
        printf("\n\n");
        printf("End of Program");
        printf("\n\n");
    }
    else {
        printf("\n\n");
        printf("The number %d is not a prime number.",num);
        printf("\n\n");
        printf("End of Program");
        printf("\n\n");
    }
    return 0;
}



No comments:

Post a Comment