C Program to print PRIME Numbers upto the given Range.
Input: Enter N Value: 11
Output: 2, 3, 5, 7, 11
C Program:
#include< stdio.h >
#include< conio.h >
void main( )
{
int i, j, n;
printf("\nEnter N Value: ");
scanf("%d", &n);
for( i = 1 ; i <= n ; i++ )
{
int c = 0 ;
for( j = 1 ; j < = i ; j++ )
{
if( i%j == 0)
{
c = c + 1;
}
}
if( c == 2 )
{
printf(" %d ", i);
if( i < n )
{
printf(",");
}
}
}
}
Output:
Enter N Value: 11
2,3,5,7,11
Input: Enter N Value: 11
Output: 2, 3, 5, 7, 11
C Program:
#include< stdio.h >
#include< conio.h >
void main( )
{
int i, j, n;
printf("\nEnter N Value: ");
scanf("%d", &n);
for( i = 1 ; i <= n ; i++ )
{
int c = 0 ;
for( j = 1 ; j < = i ; j++ )
{
if( i%j == 0)
{
c = c + 1;
}
}
if( c == 2 )
{
printf(" %d ", i);
if( i < n )
{
printf(",");
}
}
}
}
Output:
Enter N Value: 11
2,3,5,7,11
0 comments:
Post a Comment