Notification texts go here Contact Us Click here

Program that checks whether a number is prime or not using a for loop:

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated


    #include <stdio.h>
    int main()
   {
    int n, i, flag = 0;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
    for(i = 2; i <= n/2; i++)
    {
      if(n % i == 0)
     {
         flag = 1;
         break;
     }
   }
   if (n == 1)
   {
      printf("1 is neither prime nor composite.\n");
   }
   else
   {
      if (flag == 0)
         printf("%d is a prime number.\n", n);
      else
         printf("%d is not a prime number.\n", n);
   }

   return 0;
   }

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.