Write a program in C that will convert all 12 months average

Write a program in C that will convert all 12 months average temperature from Celsius to Fahrenheit. You need to create an array named avgTemp and prompt the user to input average temperature in Celsius for all 12 months. After that, you need to develop a user temperatures from Celsius to Fahrenheit and pass the array as reference and convert all temperatures from Celsius to Fahrenheit. Next, compute the average temperature of the year and assign it to a pointer variable. Finally, you return the array and from the main function, print the array along with month and yearly average. You can use loadArray and printArray functions. NEED: Comments & Indentation. Implement the program.

Solution

// C code convert temperature from celsius to fahrenheit

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

// convert to fahrenheit and update average temperatur of 12 months
double* toFahrenheit(double avgTemp[], int months, double *average)
{
int i;
double *avgfahrenheit = malloc(months);
for (i = 0; i < months; ++i)
{
avgfahrenheit[i] = 9*avgTemp[i]/5 + 32;
*average = *average + avgfahrenheit[i];
}

*average = *average/12;
return avgfahrenheit;
}

void printArray(double array[], int size)
{
int i;
for (i = 0; i < size; ++i)
{
printf(\"average temperature in fahrenheit for month %d: %lf\ \", (i+1),array[i]);
}
}

int main()
{
int i;
int months = 12;
double avgTemp[months];
double average;
double *avgfahrenheit;

for (i = 0; i < months; ++i)
{
printf(\"Enter average temperature in celsius for month %d: \", (i+1));
scanf(\"%lf\",&avgTemp[i]);
}

avgfahrenheit = toFahrenheit(avgTemp,months,&average);

printf(\"\ \");
printArray(avgfahrenheit,months);

printf(\"\ Average temperature of year: %lf\ \",average);
}

/*
output:

Enter average temperature in celsius for month 1: 31
Enter average temperature in celsius for month 2: 32
Enter average temperature in celsius for month 3: 33
Enter average temperature in celsius for month 4: 34
Enter average temperature in celsius for month 5: 35
Enter average temperature in celsius for month 6: 36
Enter average temperature in celsius for month 7: 37
Enter average temperature in celsius for month 8: 38
Enter average temperature in celsius for month 9: 39
Enter average temperature in celsius for month 10: 40
Enter average temperature in celsius for month 11: 41
Enter average temperature in celsius for month 12: 42

average temperature in fahrenheit for month 1: 87.800000
average temperature in fahrenheit for month 2: 89.600000
average temperature in fahrenheit for month 3: 91.400000
average temperature in fahrenheit for month 4: 93.200000
average temperature in fahrenheit for month 5: 95.000000
average temperature in fahrenheit for month 6: 96.800000
average temperature in fahrenheit for month 7: 98.600000
average temperature in fahrenheit for month 8: 100.400000
average temperature in fahrenheit for month 9: 102.200000
average temperature in fahrenheit for month 10: 104.000000
average temperature in fahrenheit for month 11: 105.800000
average temperature in fahrenheit for month 12: 107.600000

Average temperature of year: 97.700000


*/

 Write a program in C that will convert all 12 months average temperature from Celsius to Fahrenheit. You need to create an array named avgTemp and prompt the u
 Write a program in C that will convert all 12 months average temperature from Celsius to Fahrenheit. You need to create an array named avgTemp and prompt the u

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site