Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Description: Write a C program to store up to 30 Fahrenheit temperatures

ID: 3599168 • Letter: P

Question

Problem Description: Write a C program to store up to 30 Fahrenheit temperatures and their equivalent Celsius temperatures in two parallel arrays. Partially fill the int array with up to 30 Fahrenheit temperatures; use -100 as sentinel value to end data entry.

main() function:       

a)Declare an array of int to store up to 30 Fahrenheit temperatures in January. (use the named constant). Name this array fahr.

b)Declare a parallel array of type float to store equivalent Celsius temperatures (use the named constant). Name this array celsius.

c)Write a loop to partially fill array fahr by prompting the user in a loop. Use -100 as sentinel value.

d)Display # of values read into the array.

e)Write another loop to convert each Fahrenheit temperature in array fahr to Celsius equivalent and store it in array celsius at corresponding index. The formula is:

         C = (5 / 9)(F – 32)

f)Write a loop to display both arrays in 2 columns with column headers.

g)Compute the average Fahrenheit temperature. Display it to screen with 2 digits after the decimal point and a descriptive message.

h)Use sequential search to display all the fahr temperatures <= 40 along with the Celsius equivalent to the screen. – Inform the user if search fails.

i)Use sequential search algorithm to search for the unique Fahrenheit temperature = 0 in array fahr. Inform the user if the search fails.

Explanation / Answer

#include <stdio.h>

int main(void) {

// your code goes here

int fahr[30];

float celcius[30];

int i;

for(i =0;i<30;i++){

printf("Enter the value in fahr:");

int value = 10;

// cin>>value;

if (value == i){

break;

}else{

fahr[i] = 50;

}

}

for(int j = i; j < 30 ;j++){

fahr[j] = 0;

}

printf(" You have entered values: ");

for(int k =0;k<i;k++){

printf("%d ",fahr[k]);

}

printf("%s"," ");

//Converting the fahr values to celcius values;

for(int k =0;k<i;k++){

float value = (float)5/9 * (float)(fahr[k]-32);

celcius[k] = value;

}

printf("%s","(F) (C) ");

for(int k =0;k < i;k++){

printf("%d %f ",fahr[k],celcius[k]);

}

//Calculating the avg fahr temperature

int avgSum = 0;

for(int k =0;k < i;k++){

avgSum += fahr[k];

}

printf(" The avg Fahrenheit temperature is %.2f",(float)avgSum/i);

printf(" %s","Finding the temprature below 40 F ");

int found = 0;

for(int k =0;k < i;k++){

if(fahr[k] < 40){

found = 1;

printf("%d %f ",fahr[k],celcius[k]);

}

}

if(found == 0){

printf("%s","Couldn't find value below 40.");

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote