Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in c The prime number function int is_prime(testnum) could take

ID: 2989438 • Letter: W

Question

Write a program in c
The prime number function int is_prime(testnum) could take a provided value and decide whether
it was a prime number or not. For this exercise, extend this function to find all prime numbers for a
given range and store them in an array. Use the following function signature:
int find _primes(int startValue, int finishValue, int primeArray[], int arraySize);
The function should do the following:
1.Find all primes that are between startValue and finishValue. It should include these
limits. So for example if startValue was 5 (i.e. a prime), it should include 5 in the results.
All of these primes , or as many as can fit, should be stored in primeArray.
2. The function should return the number of primes found within the range (i.e. stored in the
array). If there are more primes than could fit in the array, then the return value should be
an error code (-1).

Explanation / Answer

TO FIND OF NUMBER IS PRIME

#include<stdio.h>

int main(){

    int num,i,count=0;
    printf("Enter a number: ");
    scanf("%d",&num);
    for(i=2;i<=num/2;i++){
        if(num%i==0){
         count++;
            break;
        }
    }
   if(count==0 && num!= 1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);
   return 0;
}

TO FIND PRIME NUMBERS IN A GIVEN RANGE

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <math.h>

void main()

{

int M, N, i, j, flag, temp, count = 0;

clrscr();

printf("Enter the value of M and N ");

scanf("%d %d", &M,&N);

if(N < 2)

{

  printf("There are no primes upto %d ", N);

  exit(0);

}

printf("Prime numbers are ");

temp = M;

if ( M % 2 == 0)

{

  M++;

}

for (i=M; i<=N; i=i+2)

{

  flag = 0;

  for (j=2; j<=i/2; j++)

  {

   if( (i%j) == 0)

   {

    flag = 1;

    break;

   }

  }

  if(flag == 0)

  {

   printf("%d ",i);

   count++;

  }

}

printf("Number of primes between %d and %d = %d ",temp,N,count);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote