Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: prime.c
- Copyright:
- Author: Mr,Kindle
- Date: 28-11-22 00:30
- Description: This code print all prime number within a given range and also print the number of total number
- of prime numbers.
- */
- #include<stdio.h>
- int main()
- {
- int n,i,j,flag,count=0;
- printf("Enter maximum range: ");
- scanf("%d",&n);
- for(i=1;i<=n;i++)//for generaitng numbers
- {
- flag=0;
- for(j=2;j<=i/2;j++)//for checking divisibility
- {
- if(i%j == 0)
- {
- flag++;
- break;
- }
- }
- if(flag == 0 && i!=1)
- {printf("%d ",i);
- count++;
- }
- }
- printf("\n\nTotal prime number between 1 & %d = %d\n",n,count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement