Friday, 19 June 2020

Prime number program 1 to 100

Q : Write a program to print all prime numbers from 1 to 100. Use nested loops, break or continue statement wherever necessary.

Answer : 



#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Prime number 1 to 100
  ##########################*/

void main()
{
     int i,j;
     clrscr();
     for(i=1;i<=100;i++)
     {
          j=2;
          while(j<i)
          {
              if(i%j==0)
                   break;
              j++;
          }
          if(i==j)
              printf("\t%d",i);
     }

     getch();
}

No comments:

Post a Comment