Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions

Question

In Problems 11 68, solve each equation. (5x 2)1/3 = 2

Answered: 1 week ago

Question

Define promotion.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago