Saturday, 5 March 2022

10. Write a program to check whether the given number is Prime or not.



#include<stdio.h>
#include<conio.h>

void main()
{
    int i,no,prime=0;
    clrscr();

    printf("enter number: ");
    scanf("%d",&no);

    for(i=1; i<=no; i++)
    {
        if(no %i == 0)
        {
            prime++;
        }
    }
    if(prime == 2)
    {
        printf("\n\n%d is a prime number",no);
    }
    else
    {
        printf("\n\n%d is not a prime number",no);
    }
    getch();
}

/*      output:

enter number: 59


59 is a prime number

*/ 

No comments:

Post a Comment

python programs

1. sum of two number