İ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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY