Q. Write a C program to find whether a number is prime or not.
Definition of prime number:A prime number is one,which is divisible only by one or itself. And its must greater than 1.
And if number is not prime, it is called composite number and vice versa.
Ans.
#include<stdio.h>
#include<stdio.h>
int main()
{
int x,num;
printf("Enter number : ");
scanf("%d",&num);
x=2;
while(x<=num-1)
{
if(num%x==0)
{
printf("Number is not prime!!");
break;
}
x++;
}
if(x==num)
printf("Number is prime!!");
getch();
getch();
return 0;
}
output of above program :
Enter number : 7
Number is prime!!
Related Programs:
No comments:
Post a Comment