On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * rn, where n is the distance (number of keys) from that key, and r is 2(1/12). Given an initial key frequency, output that frequency and the next 4 higher key frequencies.

Respuesta :

Answer:

The programming language is not stated; so, I'll solve this question using Java programming language

Comments are used for explanatory purpose

//Begin of Program

import java . util.*;

import java. math . RoundingMode;

import java . text . DecimalFormat;

public class keyfreq

{

private static DecimalFormat df = new DecimalFormat("0.00");

public static void main(String [] args)

{

 Scanner input = new Scanner(System.in);

 //Declare variable

 float f0;

//Prompt user for input

System.out.print("Enter Initial Key Frequency: ");

f0 = input.nextFloat();

//Initialize number of keys

int numkey = 1;

//Print first key frequency

System.out.print("Key Frequencies: " + df.format(f0)+" ");  

while(numkey<=4)

{

 //Calculate next frequency

 f0*= Math.pow(2,(1.0/12.0));

 //Print Frequency

 System.out.print(df.format(f0)+" ");  

  //Iterate to next frequency

 numkey++;

}

}

}

//End of Program

Explanation:

See Comments in the above program

See Attachment for source file

Ver imagen MrRoyal