C Code 31 _ To Print the Prime numbers with in the given number range



C Code 31 _ To Print the Prime numbers with in the given number range


Sample Input : 10

Sample Output  : 2 , 3 , 5 , 7 

 

Program:


#include<stdio.h>
int main()
{
                int n,i,j,f;
                printf("\nEnter a number to find prime numbers with in that number : ");
                scanf("%d",&n);
                printf("\n\nThe Prime numbers with in %d are : ",n);
                for(i=1;i<=n;i++)
                {
                                f=0;
                                for(j=1;j<=n;j++)
                                {
                                                if(i%j==0)
                                                {
                                                                f=f+1;
                                                }
                                }
                                if(f==2)
                                {
                                                printf("%d ",i);
                                }
                }
                return 0;
}




Output:








Thank You ...

Popular Posts