Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to input number is prime or not

Posted By: Mehreen Malik     Category: C Programming     Views: 11785

Program to input number is prime or not

Code for Program to input number is prime or not in C Programming

#include <stdio.h>
#include <conio.h>
    int prime(int n);
    void main()
    {
        int i,n;
        clrscr();
        printf("\n Enter The Number : ");
        scanf("%d",&n);
        i=prime(n);
        if(i==1)
            printf("\Given Number Is prime ");
        else
            printf("\n Given Number Is Not Prime ");
        getch();
    }
    int prime(int n)
    {
        int i;
        if(n<=2)
            return 1;
        elsefor(i=2;i<n;i++)
        {
            if(n%i==0)
                return 0;
        }
        return 1;
    }

/*
******
OUTPUT
******


Enter The Number : 4

Given Number Is Not Prime
*/
  
Share: 


Didn't find what you were looking for? Find more on Program to input number is prime or not Or get search suggestion and latest updates.

Mehreen Malik
Mehreen Malik author of Program to input number is prime or not is from Lahore, Pakistan.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!