Computer Science, asked by rajputjatin2110, 9 months ago

Write a program to generate prime numbers up to a specific limit.

Answers

Answered by imspidey123
0

Answer:

1. #include<stdio.h> void main()

2. { int i,j,n;

3. printf("Enter the number till which you want prime numbers\n");          scanf("%d",&n);

4. printf("Prime numbers are:-\n"); for(i=2;i<=n;i++) {

5. int c=0; for(j=1;j<=i;j++) {

6. if(i%j==0) { c++;

7. } }

8. if(c==2) { printf("%d ",i);

PLEASE MARK ME AS BRAINLIEST PLEASE!!!

Answered by shilpa85475
0

This program C is intended to generate prime numbers up to n. For instance, up to 4 prime numbers are 2,3.

Explanation:

We use two loops one to count the n and the second loop to check whether or not the number is prime.

#include<stdio.h>

void main()

{

   int i,j,n;

   

   printf("Enter the number till which you want prime numbers\n");

   scanf("%d",&n);

   

   printf("Prime numbers are:-\n");    

   for(i=2;i<=n;i++)

   {

       int c=0;

       for(j=1;j<=i;j++)

       {

           if(i%j==0)

           {

               c++;

           }

       }

         

      if(c==2)

       {

           printf("%d ",i);

       }

   }

}

Similar questions