Code Scrappers


Prime number - C Program


                    #include<stdio.h>
                    #include<stdlib.h>

                    int main()
                    {
                        int i, j, count, n;

                        printf("enter the value of n");

                        scanf("%d",&n);

                        for(i = 1;i<=n;i++)
                        {
                            count = 0;

                            for(j=2;j<=i/2;j++)
                            {
                                if(i%j==0)
                                {
                                    count++;

                                    break;

                                }

                            }

                             if(count==0 && i!= 1)

                             printf("%d ",i);

                        }

                        return 0;

                    }


                



Output

          enter the value of n : 12
          2 3 5 7 11