Sunday, 6 September 2020

Program to check weather the given number is odd or even.

/*Program to check weather the given number is prime or not*/

#include

int main()
{
int i,n,c;
       c=0;
       printf("Enter number:");
       scanf("%d",&n);

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

return 0;
}

OUTPUT:



NOTE:
Prime numbers are those numbers which have 1and itself as a factor.
Example-a)
5 only 1 and 5 are the factors of 5.So it is a prime number.
b) 6-1,2,3,6 are the factors of 6.So it is not a prime number.
DESCRIPTION:
Simply,in this program we ask the user to input a number then we divide that number with every others numbers which are less than that and is counted.If the count value is 2, it is prime number.
TRY IT YOURSELF:
Write a program to find the square and cube of a given number.

No comments:

Post a Comment

If you have any doubt, please ask in the comment section.

Search This Blog

Program to print weather the number is happy or not.

#include <stdio.h> #include <math.h> int main () { int i , j , num , temp , sum = 0 ; printf ( "Enter number\n...