To Check whether a number is prime or not
Input:-
Output:-
1)
2)
Code:-
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,i,ans;
printf("Enter a number : \n");
scanf("%d",&a);
for(i=2; i<=a/2;i++ )
ans=a%i;
{
if ( ans==0)
printf("The number is not prime ");
else
printf("The number is prime ");
}
return 0;
}
Input:-
Output:-
1)
2)
Code:-
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,i,ans;
printf("Enter a number : \n");
scanf("%d",&a);
for(i=2; i<=a/2;i++ )
ans=a%i;
{
if ( ans==0)
printf("The number is not prime ");
else
printf("The number is prime ");
}
return 0;
}
0 Comments:
Post a Comment