Q:- Write a program in C to display all the Prime Numbers up to a given limit defined by the user.
#include<conio.h>
#include<stdio.h>
void main( )
{
int num , lmt , i ;
clrscr ( );
printf (" \n Enter the limit \n");
scanf (" %d ", & lmt );
printf ("\n These are the prime numbers from 1 to %d ", lmt );
for (num=1; num<lmt; num++)
{
for (i=2; i<num; i++)
{
if (num% i = = 0)
{
break;
}
}
if (i>=num)
{
printf (" % d" , num);
}
}
getch();
}
by:- Danish Beigh
email id :- beigh.danish@gmail.com
#include<conio.h>
#include<stdio.h>
void main( )
{
int num , lmt , i ;
clrscr ( );
printf (" \n Enter the limit \n");
scanf (" %d ", & lmt );
printf ("\n These are the prime numbers from 1 to %d ", lmt );
for (num=1; num<lmt; num++)
{
for (i=2; i<num; i++)
{
if (num% i = = 0)
{
break;
}
}
if (i>=num)
{
printf (" % d" , num);
}
}
getch();
}
by:- Danish Beigh
email id :- beigh.danish@gmail.com
No comments:
Post a Comment
Tell Us What You've Got...