Question

In: Computer Science

In C Program The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17,...

In C Program

The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31.

A positive integer between 1 and 1000 (inclusive), other than the first 11 prime integers, is prime if it is not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31.

Write a program that prompts the user to enter a positive integer between 1 and 1000 (inclusive) and that outputs whether the number is prime.

If the number is not prime, then output all the numbers, from the list of the first 11 prime integers, which divide the number.

Example (Numbers with underscore indicate an input):

Enter an integer between 1 and 1000 (inclusive): 62
62 is divisible by 2, 31.
62 is not prime.

--------------------------------------------

Enter an integer between 1 and 1000 (inclusive): -1
You must enter a number between 1 and 1000 (inclusive).

--------------------------------------------

Enter an integer between 1 and 1000 (inclusive): 1206
You must enter a number between 1 and 1000 (inclusive).

Solutions

Expert Solution

#include<stdio.h>
int isPrime(int num)
{
   int i;
   if (num <= 1) return 0;
   if (num % 2 == 0 && num > 2) return 0;
   for (i = 3; i < num / 2; i += 2)
   {
      if (num % i == 0)
         return 0;
   }
   return 1;
}

int main() {
   int n, i, f;
   printf("Enter an integer between 1 and 1000 (inclusive): ");
   scanf("%d", &n);
   
   if(n>=1 && n<=1000){
      if(isPrime(n)){
         printf("%d is prime.\n",n);
      }
      else{
         f = 0;
         printf("%d is divisible by ",n);
            
         for(i = 2;i<n;i++){
            if(n%i==0){
               if(f == 0){
                  printf("%d",i);    
               }
               else{
                  printf(", %d",i);  
               }
               f = 1;
            }
         }
         printf(".\n");
         printf("%d is not prime.\n",n);
      }
   }
   else{
      printf("You must enter a number between 1 and 1000 (inclusive).\n");
   }
   
   return 0;
}


Related Solutions

Answer all the question below. Table 2: 1 3 5 7 9 11 13 15 17...
Answer all the question below. Table 2: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 12.2373551424579 11.7708440253038 11.3114033194700 11.0981090241345 10.9917532871426 10.9633449623870 10.9328985186904 11.0609123182770 11.1447150124713 11.2994243413533 11.4699411879533 11.5862580969086 11.7887055678588 11.9277833926721 11.9332325617172 12.0027754228957 12.0455191817870 11.9895076044597 12.1161492247957 11.9142999902406 11.9523445384738 11.8444716643177 11.8325572681845 11.6394782554936 11.4409836766153     Visualize data in table 2 in a 2-dimensional plot using Matlab.     Interpolate data in table 2 to determine a value of...
A B C 13 7 9 29 19 54 25 54 5 17 15 11 21...
A B C 13 7 9 29 19 54 25 54 5 17 15 11 21 22 20 a) Construct ANOVA table and test the null hypothesis: μA = μB = μC b) Assume that you have statistically enough evidence to reject the null hypothesis; suggest an approach to find out whether all three means are different than each other or only one of them is different than others (while the other two means are equal) and if the second...
Consider the data. xi 1 2 3 4 5 yi 4 7 5 11 13 (a)...
Consider the data. xi 1 2 3 4 5 yi 4 7 5 11 13 (a) Compute the mean square error using equation  s2 = MSE = SSE n − 2  . (Round your answer to two decimal places.) (b) Compute the standard error of the estimate using equation s = MSE = SSE n − 2  . (Round your answer to three decimal places.) (c) Compute the estimated standard deviation of b1 using equation sb1 = s Σ(xi − x)2...
Calculate the five-number summary of the given data. 11 7 2 17 18 2 13 22...
Calculate the five-number summary of the given data. 11 7 2 17 18 2 13 22 16 1 20 21 20 23 24
Problem 1 (4+3 marks). (a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20,...
Problem 1 (4+3 marks). (a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Mergesort. Count the number of comparisons made. (b) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Heapsort.
Match No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14...
Match No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Player A 8 42 56 68 91 123 12 46 57 137 5 80 14 10 19 Player B 38 44 46 59 57 61 48 42 51 39 58 41 55 45 68 1. For the given data set representing the runs scored by two players in last 15 matches, conduct the following analysis: i. Which average you will use to summarize...
443 Consider the data set: 8 4 3 6 17 15 13 7 21 11 32...
443 Consider the data set: 8 4 3 6 17 15 13 7 21 11 32 1 1. 1.What is the percentile rank of xi = 21? 2. What is the value corresponding to the 61th percentile, P61? 3. Find outliers, if exist.
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13,...
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 . . . See the pattern? Each element in the series is the sum of the preceding two elements. Here is a recursive formula for calculating the nth number of the sequence: Fib(N) = {N, if N = 0 or 1 Fib(N - 2) + Fib(N - 1), if N > 1 a) Write a recursive method fibonacci that returns...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of Aides Absent 5 8 11 15 4 2 7 1 4 6 14 19 3 5 8 In which of the following ranges you can find the Upper Control Limit of the control chart? 0.1427 0.1536 0.1677 Not computable with information available In which of the following ranges you can find the Lower Control Limit of the control chart? Does not exit...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Test score 67 67 87 89 87 77 73 74 68 72 58 98 98 70 77 Above we have the final averages of the last stats and I want to know if the class average falls within the boundaries of all my statistics classes for the past 20 years. Find the sample size, mean, and standard deviation of the data above (Table 1)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT