0
6.6kviews
Write a program to generate prime numbers between 1 and 100.
1 Answer
0
1.0kviews

Algorithm:

  • Start.
  • Initialize array a, i, j = 2.
  • for(i=0; i<100; i++)
  • Set a[i] to i+1;
  • for(i=0; i<100; i++) and
  • for(j=2; a[i]>j; j++)
  • If a[i]%j is equal to 0 then break.
  • Else if(a[i]==j || a[i]==1)
  • Then print Prime number between particular given range is.
  • Stop.

Program:

#include <stdio.h>
#include <conio.h>
int main(){
int a[100], i, j=2;

for(i=0; i<100; i++)
a[i]=i+1;

    printf("Prime Number between 1 and 100:\n");

    for(i=0; i<100; i++) 
    {
for(j=2; a[i]>j; j++)   
{
    if(a[i]%j==0)
    break;
    }

if(a[i]==j || a[i]==1) 
{
        printf("%d\t", a[i]);
    }
getch();
}

enter image description here

Please log in to add an answer.