Home Uncategorized prime numbers from 1 to n

prime numbers from 1 to n


Here we written code for print first ‘n’ primes.

For improvement of your coding skills we give some tasks along this. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. we will display your details(like Name, City, college, photo) in our site.

Task : Write a c program to print all primes from first ‘n’ natural number.

Write a C Program to display 1 to n prime numbers.

int main()
   int a,i,x=1,count,c=0; //’a’ is user defined number, ‘i’ for iteratiions, ‘count’ for counting factor of given number, ‘x’ represents current number in itaration, ‘c’ for counting number of primes calculated.
   printf(“Enter a number :”);
   scanf(“%d”,&a); //Read number of primes required
   printf(“The first %d primes are :\n”,a);
      count=0; //set count as zero to count factors of current number (x).
         if(x%i==0) //check the iteration value is factor of current number or not.
      if(count==2) //Every prime number should have only two factors.
   return 0;

Output :
Enter a number : 30
The first 30 primes are :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 71 73 79 83 89 97 101 103 107 109 113

Find Whether the Given Number is Prime Number or not.

Back to the programs list.

Task Achievers

Till now no one is answered.