Search This Blog


Saturday, 13 April 2019

Program to find PRIME NUMBERS IN Language C

WELCOME BACK TO codejunction.in , hope you are having a pleasant day. 


IN THIS PROGRAM THE USER NEEDS TO ENTER A NUMBER AND THE PROGRAM WILL PRINT ALL PRIME NUMBERS TILL THAT NUMBER.


CODE

#include<stdio.h>
void main()
{
    int n,i,fact,j;
    printf("Enter the Number");
    scanf("%d",&n);
    printf("Prime Numbers are: \n");
    for(i=1; i<=n; i++)
    {
        fact=0;
        for(j=1; j<=n; j++)
        {
            if(i%j==0)
                fact++;
        }
        if(fact==2)
            printf("%d " ,i);
    }
    getch();
}

OUTPUT



No comments:

Post a Comment