Advertisement
Mr_kindle

prime.c

Nov 27th, 2022 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. /*
  2.     Name: prime.c
  3.     Copyright:
  4.     Author: Mr,Kindle
  5.     Date: 28-11-22 00:30
  6.     Description: This code print all prime number within a given range and also print the number of total number
  7.     of prime numbers.
  8. */
  9.  
  10.  
  11. #include<stdio.h>
  12. int main()
  13. {
  14.   int n,i,j,flag,count=0;
  15.   printf("Enter maximum range: ");
  16.   scanf("%d",&n);
  17.   for(i=1;i<=n;i++)//for generaitng numbers
  18.     {
  19.       flag=0;
  20.       for(j=2;j<=i/2;j++)//for checking divisibility
  21.         {
  22.           if(i%j == 0)
  23.             {
  24.               flag++;
  25.               break;
  26.             }
  27.         }
  28.       if(flag == 0 && i!=1)
  29.           {printf("%d ",i);
  30.            count++;
  31.           }
  32.     }
  33.     printf("\n\nTotal prime number between 1 & %d = %d\n",n,count);
  34.    
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement