İN C PROGRAMMİNG Write a 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, ??+1 ={|(?? +??) ???1000|, ?????2=0. |(?? − ??) ??? 1000|, ????? 2 = 1 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 ???????? ????? ?? (?? + ??) ??? 1000 If ????? 2 = 1, ??+1 equals ???????? ????? ?? (?? − ??) ??? 1000

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
İN C PROGRAMMİNG
Write a 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,
??+1 ={|(?? +??) ???1000|, ?????2=0. |(?? − ??) ??? 1000|, ????? 2 = 1
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 ???????? ????? ?? (?? + ??) ??? 1000 If ????? 2 = 1, ??+1 equals ???????? ????? ?? (?? − ??) ??? 1000
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education