Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that fills an integer array of size 1000 with random positive integers between 1 and 10. Assume that each element represents

Write a C program that fills an integer array of size 1000 with random positive integers between 1 and 10. Assume that each element represents a different city and the integers stored in the array represent the number of golds in those cities. The program traverses over the array and collects the golds at each city, starting from a random position. When the program visits a certain city, all of the golds are collected, and the visited element of the array becomes 0 (no gold is left at that city.) The journey continues with the rule given below. If the position at the nth step is denoted by pn, and the number of golds at the city pn is denoted by gn,

The program continues visiting cities until the last three visited city has no gold. The program, at each visit, should print out the following information:

The current city index (pn).

The previous city index (pn-1).

The number of golds at the current city (gn).

The current total gold collected.

The number of cities visited.

During the journey, if the following conditions arise, the given rules apply:

If the total number of golds collected becomes a perfect square after a visit, then the program should print PERFECT! and the total number of golds are doubled (x2).

If the total number of golds collected becomes a prime number after a visit, then the program should print PRIME! and the total number of golds are tripled (x3).

In your program, try to follow the principles below:

Avoid using magic numbers or hard-coded values. Define macros if necessary.

Avoid writing too long functions (including main ()).

Use as few global variables as you can.

Avoid code repetition +1 calculated as:

If 2 = 0, +1 equals ((1 + + ) 1000

If 2 = 1, +1 equals ((1 + ) 1000

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

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions