1.

Write an algorithm where you input a number and it says whether it is a prime number or not.

Answer»

Explanation:

/*Check given number is PRIME number or not*/

#include

void main(){

INT num,i,count=0;

PRINTF("Enter a number: ");

scanf("%d",&num);

for(i=2;i<=num/2;i++){

if(num%i==0){

count++;

BREAK;

}

}

if(count==0 && num!= 1)

printf("%d is a prime number",num);

else

printf("%d is not a prime number",num);

return 0;

}



Discussion

No Comment Found