To check whether the Given Number is Prime or not using while loop

 Program:


#include<stdio.h>
#include<conio.h>
void main()
{
    int n, i=1, count=0;
    clrscr();
    printf("Enter any Number : ");
    scanf("%d", &n);
    while(i<=n)
    {
        if(n%i==0)
            count++;
        i++;
    }
    if(count==2)
        printf("Given Number is Prime");
    else
        printf("Given Number is nor Prime");
    getch();
}

Output:


Ex-1:
Enter any Number : 19
Given Number is Prime

Ex-2:
Enter any Number : 15
Given Number is not Prime

Ex-3:
Enter any Number : 149
Given Number is Prime

Ex-1:
Enter any Number : 133
Given Number is not Prime



Next Topic        :  

Previous Topic :

No comments:

Post a Comment