Computer Science, asked by Anonymous, 1 year ago

write a c++program to print prime no's between 1 and 100?


Shravani83: Ty Dear :)

Answers

Answered by Shravani83
0
The c++ program is:

/*C program to print 1 to 100 prime numbers*/
int main()
{
 int num,n,div,p;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(n=2; n<=num; n++)
 {
  for(div=2; div<n; div++)
  {
   if(n%div==0)
   {
     p=0;
     break;
   }
   p=1;
  }
  if(p)
    printf("\t%d",n);
 }
 getch();
 return 0;
}
Answered by vermacharu
0
#include <stdio.h>
#include <conio.h>
void main()
{
  int a[100],i,j=2;
  clrscr();
  for(i=0;i<100;i++)
   a[i]=i+1;
printf("Prime Number between 1 to 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();
}
Similar questions