1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<stdio.h>
void prime(int);
void main()
{
int num;
printf("Enter a Number up to which the prime numbers to be printed:- ");
scanf("%d",&num);
prime(num);
}
void prime(int a)
{
int i,j;
printf("1\t2\t");
for (i=3;i<=a;i++)
{
for (j=2;j<i;j++)
{
if ((i%j)==0)
break;
}
if(i==j)
printf("%d\t",i);
}
}
|
Here we ask users for the max number up to which we need to print out the prime number and from there. we Pass that value to The function and Display the value.
0 comments:
Post a Comment