Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C language please. Thanks. SE-1105 HOMEWORK-2 . Write a program that fills an integer array of size 1000 with random positive integers between 1

image text in transcribed
In C language please. Thanks.
SE-1105 HOMEWORK-2 . 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 Pa and the number of golds at the city Pris denoted by 8 Pw= {! (Con-17 Pn+) mod1000) , 9xmod 2 = 0 (CPn-1 + Pn - 9n) mod 1000. gn mod 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 (ph). The previous city index (pr). The number of golds at the current city (8). 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 "PERFECTI" 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 "PRIMEI" 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 Pn calculated as: If 9.mod 20. Per equals absolute value of (CP-1 + P + 9.) mod 1000 If onmod 2 = 1. Pn+1 equals absolute value of GP-1 + P.-9.) mod 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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

Excel caculation on cascade mental health clinic

Answered: 1 week ago