Answer:
#include <stdio.h>
int main()
{
float your_value1, your_value2, your_value3, your_value4, your_value5;
printf("Enter a frequency: ");
scanf_s("%f", &your_value1);//storing initial key frequency in your value 1
float r = 2.0 / 12;//typing 2.0 so it is treated as float and not int
your_value2 = your_value1 * r * 1; //initial*r*n
your_value3 = your_value1 * r * 2; //initial*r*n
your_value4 = your_value1 * r * 3; //initial*r*n
your_value5 = your_value1 * r * 4; //initial*r*n
printf("%0.2f %0.2f %0.2f %0.2f %0.2f", your_value1, your_value2, your_value3, your_value4, your_value5);
return 0;
}
Explanation:
The purpose of this exercise is to make you understand the difference between float and int. float variables are used when you need decimals in your calculations. int is used when you need integers. The problem in this exercise was the formulation of r. Now r is = 2/12, this means that when we type r as that, the computer assumes that it is an integer and treats it as such. So, it will convert the 0.166667 into 0. To overcome this, all you have to do is type 2.0 instead of 2 alone.
The %0.2 command restricts the float variable to 2 decimal places. By default, it has 6 decimal places.
I have used the function scanf_s instead of scanf simply because my compiler does not work with scanf.