Program:
#include<stdio.h>
//#include<math.h>
//#include<conio.h>
main()
{
int i,a,b,j,flag=1;//clrscr();
printf("\nEnter the limit:\n");
scanf("%d%d",&a,&b);
for(i=a;i<=b;i++)
{
if (i==0||i==1)
continue;
flag=1;
for(j=2;j<=(i/2);j++) //sqrt(i) can be used.
{
if(i%j==0)
{
flag=0;
}
}
if(flag==1)
{
printf("%d\t",i);
}
}
// getch();
printf("\n");
}
Output:
nn@linuxmint ~ $ gcc c3.c
nn@linuxmint ~ $ ./a.out
Enter the limit:
1
10
2 3 5 7
nn@linuxmint ~ $
#include<stdio.h>
//#include<math.h>
//#include<conio.h>
main()
{
int i,a,b,j,flag=1;//clrscr();
printf("\nEnter the limit:\n");
scanf("%d%d",&a,&b);
for(i=a;i<=b;i++)
{
if (i==0||i==1)
continue;
flag=1;
for(j=2;j<=(i/2);j++) //sqrt(i) can be used.
{
if(i%j==0)
{
flag=0;
}
}
if(flag==1)
{
printf("%d\t",i);
}
}
// getch();
printf("\n");
}
Output:
nn@linuxmint ~ $ gcc c3.c
nn@linuxmint ~ $ ./a.out
Enter the limit:
1
10
2 3 5 7
nn@linuxmint ~ $
0 comments:
Post a Comment