Prolog The recent population (in million) and the area (in million of square kil
ID: 3805076 • Letter: P
Question
Prolog
The recent population (in million) and the area (in million of square kilometers) of six countries are given in the following table: The density of population is obtained if we divide the population of country by the area of country. You have to write a Prolog program that finds the maximum density of population and displays the result india has the maximum density of 417.241 as follows: 1. Make facts for the population or each country, followed by the facts for the area of each country. 2. Make the rule density([Country, Density]) that returns a country-density pair as a list [Country, Density] 3. Make the rule makelist(CDIist) that creates the list of all country-density pairs (CDlist) 4. Make the rule listmax(CDlist, [Cmax,Dmax]) that returns the pair of country Cmax with the maximum density Dmax 5. Make the rule maxden that computes and displays the final result (india has the maximum density of 417.241)Explanation / Answer
ANS:: PROGRAM
pop(usa,314).
pop(india,1210).
pop(china,1347).
pop(brazil,193).
pop(indonesia,237)
pop(japan,127)
area(usa,9.1). /* millions of square miles */
area(india,2.9).
area(china,9.5).
area(brazil,8.4).
area(indonesia,1.8).
area(japan,0.36).
density(X,Y) ::- The population-density of a country X is Y, if:
pop(X,P), The population of X equals to P or P, and
area(X,A), Area of the X is A, and
Y is P/A. Y is calculated by dividing P by A.
example o/p::
- consult(population).
% population compiled 0.00 sec, 1,548 bytes
Yes
?- density(brazil,D).
D = 22.976
Yes
?- density(china,D).
D = 141.789
Yes
In simple way:::
pop(INDIA, 1210).
area(INDIA, 2.9).
density(X,Y): The population density of a country X is Y if: pop(X,P),
area(X,A),
Y is P/A
SAMPLE O/P WILL BE
: density(INDIA X).
X=417.24
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.