write a c++program to print prime no's between 1 and 100?
Shravani83:
Ty Dear :)
Answers
Answered by
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;
}
/*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
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();
}
#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
Computer Science,
8 months ago
Chemistry,
1 year ago