Question

C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day:...

C

Part 1

Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day:

typedef struct {

      char DayOfMonth[31];     /*  e.g.  “May 13”,  “July 9”  */

      int HighTemp;         /*  the highest temperature of that day  */

      int LowTemp;         /* the lowest temperature of that day */

} DayTemp;

DayTemp  Temperature[365];

Temperature is an array of structure DayTemp.  Write a function that will return the average of HighTemp for a given number of days (NumberDay) since January 1st. For example, HighAverage( Temperature, 32) will return the average of HighTemp from Jan. 1st until Feb. 1st.  The function heading is

         int   Average ( structure DayTemp Temperature[ ], int NumberDay)

         {

         }

Part 2

Write a program that uses a loop to read a series of integer numbers until encountering a zero. Within the loop, the program calls a function named Sum that uses the integer number as an argument. The function Sum calculates and returns the sum of even integers from 2 to that number.
Sample Run:

            Enter a positive integer number ( 0 to stop):

            6

            This sum of even numbers from 2 to 6 is 12.

           

            Enter a positive integer number ( 0 to stop):

            5

            This sum of even numbers from 2 to 5 is 6.

            Enter a positive integer number ( 0 to stop):

            0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

1)

int Average(struct DayTemp Temperature[],int NumberDay ){

int totalTemperature=0; // will store the total summation of high temperature

// iterate from index 0 to numberday-1
int subscript;
for( subscript=0; subscript<NumberDay;subscript++){

// keep adding the high temperature for that subscript

totalTemperature+= Temperature[subscript].HighTemp;

}

return totalTemperature/NumberDay;// divide the sum by the number of day to get the average

}

2)

#include <stdio.h>
int sum(int n)
{
int i,s=0;
for(i=2;i<=n;i=i+2)
{
s=s+i;
}
return s;
}

int main(){
int num;
printf("Enter a positive integer number ( 0 to stop): ");

scanf("%d",&num);
while(num!=0)
{

printf("This sum of even numbers from 2 to %d is %d.\n",num,sum(num));
printf("Enter a positive integer number ( 0 to stop): ");

scanf("%d",&num);
}

}

ㅃ main.c-Code:Blocks 13.12 Eile Edit iew Search Project Build Debug Fortran woSmith Tools ToolsPlugins DoxyBlocks Settings He

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertain...

    The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertaining to the lines: cin>>month[i].lowTemp; and months[i].avgTemp = (months[i].highTemp + month[i].lowTemp)/2; The error messages read as follows: error C2039: 'lowTemp': is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' and it continues. The second error message is identical. The program is as follows: Ch. 11, Assignment #3. pg. 646. Program #4. //Weather Statistics. //Write a program that uses a structure to store the...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program...

    ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Change your C++ average temperatures program to: In a non range-based loop Prompt the user for...

    Change your C++ average temperatures program to: In a non range-based loop Prompt the user for 5 temperatures. Store them in an array called temperatures. Use a Range-Based loop to find the average. Print the average to the console using two decimals of precision. Do not use any magic numbers. #include<iostream> using namespace std; void averageTemperature() // function definition starts here {    float avg; // variable declaration    int num,sum=0,count=0; /* 'count' is the int accumulator for number of...

  • Please write a C++ program that will accept 3 integer numbers from the user, and output...

    Please write a C++ program that will accept 3 integer numbers from the user, and output these 3 numbers in order, the sum, and the average of these 3 numbers. You must stop your program when the first number from the user is -7. Design Specifications: (1) You must use your full name on your output statements. (2) You must specify 3 prototypes in your program as follows: int max(int, int, int); // prototype to return maximum of 3 integers...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT