Q:

C Program to print all prime numbers from 1 to N

0

C Program to print all prime numbers from 1 to N

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
int checkPrime(int num){
    int i;
    int flg=0;
   
      number will not be prime.*/
    for(i=2;i<(num-1);i++)
    {
        if(num%i==0){
            flg=1;
            break;
        }
    }
    if(flg) return 0;
    else return 1;
}
 
int main()
{
    int i,n;
 
    printf("Enter the value of N: ");
    scanf("%d",&n);
 
    printf("All prime numbers are from 1 to %d:\n",n);
    for(i=1;i<=n;i++)
    {
        if(checkPrime(i))
            printf("%d,",i);
    }
     
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now