Advertisement
Realratnadwip

Prime Number

May 16th, 2025
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6.     int num, i, flag;
  7.     printf("This is a simple program to check Prime Number.\n\n");
  8.     printf("Enter the number to check : ");
  9.     scanf("%d", &num);
  10.  
  11.     flag = 0;
  12.  
  13.     if(num <= 1)
  14.     {
  15.         flag = 1;
  16.     }
  17.  
  18.     for(i = 2; i <= num / 2; i++)
  19.     {
  20.         if(num % i == 0)
  21.         {
  22.             flag = 1;
  23.             break;
  24.         }
  25.     }
  26.  
  27.     if(flag == 0)
  28.     {
  29.         printf("%d - is a Prime Number.", num);
  30.     }
  31.     else
  32.     {
  33.         printf("%d - is not a Prime Number.", num);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement