To print all prime lying between (n,2) in C
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/*
Algo:
1.input num.
2.check remainder of every number lying (1,num) by dividing it with its all previous number using for loop.
3.if % != 0 then
*/
int main()
{
int num, count = 0;
printf("Enter the number : ");
scanf("%d", &num);
for (int i = num; i >= 2; i--)
{
for (int j = i - 1; j >= 2; j--)
{
if (i % j != 0)
{
count = count + 1;
}
else
{
continue;
}
}
if (count == i - 2)
{
printf("%d ", i);
count = 0;
}
else
{
count = 0;
continue;
}
}
return 0;
}
Comments
Post a Comment