Code Competitions

Coding competition

Sunday, 12 May 2013

Program to find number of prime numbers entered by user.

#include<stdio.h>
#include<conio.h>
void main()
{
    int a,n,i=0,j,b,flag=1;
    clrscr();
    printf("enter number of prime number needed");
    scanf("%d",&n);
    a=2;
    while(i<n)
    {
    for(j=2;j<a-1;j++)
    {
        if(a%j==0)
        {
            flag=0;
            break;
        }
        else
        {
            flag=1;
            continue;
        }
    }
    if(flag==1)
    {
        printf("\t%d",a);
        a++;
        i++;
    }
    else
    {
        a++;
    }
    }
    getche();
}

No comments:

Post a Comment