Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

a program for first n number of prime numbers

0 votes
asked Aug 3, 2018 by amin T (120 points)

2 Answers

0 votes
answered Aug 3, 2018 by anonymous
#include<stdio.h>

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
    int n,i = 3, count, c;

    printf("\nEnter the number of prime numbers required :  ");
    scanf("%d", &n);

    if(n >= 1)
    {
        printf("\n\nFirst %d prime numbers are :  ", n);
        printf("2 ");
    }

    // iteration for n prime numbers
    // i is the number to be checked in each iteration starting from 3
    for(count = 2; count <= n; i++)  
    {
        // iteration to check c is prime or not
        for(c = 2; c < i; c++)
        {
            if(i%c == 0)
                break;
        }

        if(c == i)  // c is prime
        {
            printf("%d ", i);
            count++;    // increment the count of prime numbers
        }

    }
    printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}
0 votes
answered Aug 3, 2018 by Anusha Patel (140 points)
#include<stdio.h>

int main()

{int n,i,count=0,j;

printf("enter the no. upto which u want to print");

scanf("%d",&n);

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

{

{

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

{        if(i%j==0)

count++;

}}

if(count==2)

printf("prime no. %d\n",i);

count=0;

}

return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...