Que:
Write a program that accepts a number from the user and prints prime numbers from 0 to that
number.
Ans:
The prime number is a positive integer greater than 1 that is only divisible by 1 and itself. For example 2, 3, 5, 7, 11 are the first five prime numbers.
Code:
Write a program that accepts a number from the user and prints prime numbers from 0 to that
number.
Ans:
The prime number is a positive integer greater than 1 that is only divisible by 1 and itself. For example 2, 3, 5, 7, 11 are the first five prime numbers.
Code:
#include<stdio.h>
void main()
{
int n,i,test,j;
printf("Enter the Number=");
scanf("%d",&n);
printf("Prime Numbers are: \n");
for(i=1; i<=n; i++)
{
test=0;
for(j=1; j<=n; j++)
{
if(i%j==0)
test++;
}
if(test==2)
printf("%d " ,i);
}
getch();
}
No comments:
Post a Comment