Question : Write a C Program to check whether a number is prime or not.
/*
Write a C Program to check whether a number is prime or not.
*/
#include <stdio.h>
main()
{
int n, i, c = 0;
printf("Enter any number n:");
scanf("%d", &n);
/*logic*/
for (i = 1; i <= n; i++)
{
if (n % i == 0)
{
c++;
}
}
if (c == 2)
{
printf("n is a Prime number");
}
else
{
printf("n is not a Prime number");
}
return (0);
}
OUTPUT :
Enter any number n: 7
n is Prime number
Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.
Please do comment and share.
Thank You.
Please do comment and share.
Thank You.
No comments:
Post a Comment