Question

In: Computer Science

-In C Programming- Write a program to display the total rainfall for a year. In addition,...

-In C Programming-

Write a program to display the total rainfall for a year. In addition, display the average monthly rainfall, and the months with the lowest and highest rainfall.

Create an array to hold the rainfall values. Create a 2nd parallel array (as a constant) to hold the abbreviated names of the months. I created my arrays to be 1 element bigger than needed, and then disregarded element [0] (so that my months went from [1] = "Jan" to [12] = "Dec").

Populate the array with the rainfall values entered by the user. Then, display the rainfall values. Display the 1st 6 months, followed by the last 6 months Then display the statistics (the total, average, lowest, and highest rainfall).

Calculate the total rainfall. After you get the total, you should be able to calculate the average (use the size (minus 1 if the array was 1 element bigger than needed) of the array). Then find the index of lowest rainfall and the index of highest rainfall. Finally, display the statistics, using the indexes that were found to get the lowest and highest rainfall value and the name of the month from the arrays.

Format the output to 1 decimal place.

There is no validation.

Solutions

Expert Solution

Program:

#include<stdio.h>

int main()
{
int i,lowest=0,highest=0;
double values[12];
double min,max;
double total=0.0,average;

const char *month[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

printf("\nEnter Rainfall of each of 12 months: \n");

for(i=0;i<=11;i++)
{
scanf("%lf",&values[i]);
}

max=values[0];
min=values[0];

printf("\nMonth and its rainfall value: \n\n");
for(i=0;i<=11;i++)
{
printf("%s : %.2lf\n",month[i],values[i]);
if(max<values[i])
{
max=values[i];
highest=i;
}
if(min>values[i])
{
min=values[i];
lowest=i;
}
total=total+values[i];
}

average=total/12;


printf("\nTotal rainfall for the year : %.1lf\n",total);
printf("\n\nThe average monthly rainfall : %.1lf\n",average);
printf("\n\nThe month %s with the highest rain ie %.1lf\n",month[highest],max);
printf("\n\nThe month %s with the lowest rain ie %.1lf\n",month[lowest],min);

return 0;
}

Output:


Related Solutions

Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year,     the average monthly rainfall,     and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November,...
Write a C++ program to display toy name
Write a C++ program to display toy name
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
C Programming Write a program in C that reads in a file, stores its contents as...
C Programming Write a program in C that reads in a file, stores its contents as a character array/pointer (char*) into an unsigned character array/pointer (unsigned char* message). Note: the input file can have one line or multiple lines and vary in length
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT