Question
please write this program in C The code below outputs prime numbers in specified ranges. Rewrite the program so it produces the same output, except
please write this program in C
The code below outputs prime numbers in specified ranges. Rewrite the program so it produces the same output, except create two new functions that eliminate redundant code. The first function should take as input an integer n and return whether or not it is a prime number. The second function should take as input two integers that specify a number range, test if each number in the range is prime using the first function, and if it is prime then output it. It doesn't need to return anything. Finally, the main function should be modified to use your prime range function. Be sure to include function prototypes.
#include "stdio.h"
int main() { int isDivisible;
printf("Prime numbers between 10 and 20 "); for (int i = 10; i => { isDivisible = 0; for (int j = 2; j { if (i % j == 0) { isDivisible = 1; break; } } if (!isDivisible) { printf("%d ",i); } } printf(" ");
printf("Prime numbers between 100 and 200 "); for (int i = 100; i => { isDivisible = 0; for (int j = 2; j { if (i % j == 0) { isDivisible = 1; break; } } if (!isDivisible) { printf("%d ", i); } } printf(" ");
printf("Prime numbers between 1000 and 1050 "); for (int i = 1000; i => { isDivisible = 0; for (int j = 2; j { if (i % j == 0) { isDivisible = 1; break; } } if (!isDivisible) { printf("%d ", i); } } printf(" ");
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started