diff --git a/C/Program-61/program.c b/C/Program-61/program.c new file mode 100644 index 00000000..0e7c906c --- /dev/null +++ b/C/Program-61/program.c @@ -0,0 +1,58 @@ +/* + This Program calulates all the prime between the range of numbers + includes the numbers which is provided. + + For e.g: 2 7 + Prime Numbers are : 2 3 5 7 +*/ + +#include +#include + +char primecheck(int); + +int main() +{ + int i,num1,num2,cases; + char ans; + printf("Enter Number of Test Cases: "); + scanf("%d",&cases); + while (cases--) + { + printf("Enter First Number: "); + scanf("%d",&num1); + printf("Enter Second Number: "); + scanf("%d",&num2); + + printf("Answer: "); + for(i=num1;i<=num2;i++) + { + ans = primecheck(i); + if (ans == 'y') + printf("%d ",i); + } + printf("\n"); + } + return 0; +} + +char primecheck(int num) +{ + int i; + if (num == 0 || num == 1) + return 'n'; + else + { + for(i=(num-1);i>1;i--) + { + if(num%i == 0) + { + return 'n'; + } + else + continue; + } + return 'y'; + } + +} \ No newline at end of file diff --git a/C/README.md b/C/README.md index 936b65b6..f5d269b5 100644 --- a/C/README.md +++ b/C/README.md @@ -62,6 +62,7 @@ | Program-58 | Program to find the sum of elements between indexes | | Program-59 | Program to Search Students details in a list | | Program-60 | Program to print kaprekar number in a given range | +| Program-61 | Program to find the all the prime numbers between the numbers |