Write a program in C to test a number prime or non-prime.

Write a program in C to test a number prime or non-prime.

Write a program in C to test a number prime or non-prime.

/*
Author : Sabya Roy
*/

 

#include <stdio.h>
#include <stdlib.h>

int main()
{
           int n,i,p=1;                                      // initialization of variable
           printf(“Enter the number: “);    //Show the dialog
           scanf(“%d”,&n);
           for(i=2; i<n ; i++)                        //Using for loop
                      if(n%i==0){
                      p=0;
                      break;
                      }




           if(p==1)printf(“\nPrime!”);    //if prime show this
           else printf(“\nNonPrime!”);   //if non prime show this
           getch();
}

———————————————————————————————————————————————————-

Output :

Enter the number : 4
NonPrime!

———————————————————————————————————————————————————-

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *