Posts

Showing posts from June, 2022

Write a program to check if a number is prime or not.

 //program to check if a number is prime or not. //number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7) // 0 and 1 are not prime numbers. // 2 is the only even prime number. #include<stdio.h> int main() {     int n , a;          printf("enter any number\n");          scanf("%d", &n);          for(int i=1; i<=n; i++){ /*for loop is executed until the i value is equal to i*/ if(i%n==0){ a++; /* a will get increment if  i%n=0 */ } } if(a==2){ printf("n is a prime number"); }          else{         printf("n is not a prime number"); }          return 0; } output : enter any number 5 n is not a prime number -------------------------------- Process exited after 8.33 seconds with return value 0 Press any key to continue . .