C Programming
QUESTION 9
Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style.
Your program will calculate and print a new value based on the command that's entered, as follows:
If the user enters any other command, your program should print an error message that contains the invalid character. This program does not need to test for any other errors.
If you don't know how to calculate any of those statistics, a quick web search should help you find the answers.
Your output should match the format of the test cases shown below exactly. In each test case, the sample input values are underlined.
TEST CASE 1:
Enter input vals: 6 16 20 19 Enter command: A Average: 15.250
TEST CASE 2: Enter input vals: 5 -5 10 -2 Enter command: s Standard deviation: 5.874 TEST CASE 3: Enter input vals: 9 12 -1 3 Enter command: M Maximum value: 12 TEST CASE 4 Enter input vals: 15 9 27 3 Enter command: T Invalid command T
The below is the c code for the given requirement.
#include <stdio.h>
int main()
{
int a,b,c,d,sum,max;
int avg,i;
int i1,b1,c1,d1;
int count,mean,sod,variance,standev;
char val;
printf("Enter input vals:");
scanf("%d%d%d%d",&a,&b,&c,&d);
i=a;
printf("Enter command:");
scanf("%s",&val);
switch (val)
{
case 'A':
sum=(i+b+c+d);
avg=(sum/4);
printf("Average:%d\n",avg);
break;
case 'S':
count=4;
sum=(i+b+c+d);
mean=sum/4;
i=i-mean;
b=b-mean;
c=c-mean;
d=d-mean;
i1=i*i;
b1=b*b;
c1=c*c;
d1=d*d;
sod=i1+b1+c1+d1;
variance=sod/4;
standev=sqrt(variance);
printf("Standard deviation:%d\n",standev);
break;
case 'M':
max=((i>b? i:b) > (c>d? c:d) ? (i>b?
i:b) : (c>d? c:d));
printf("Maximum value:%d\n",max);
break;
default:
printf("Invalid command\n");
break;
}
}
C Programming QUESTION 9 Write a program that prompts for and reads four integer input values,...
C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...
Question 01: Write a Java program that prompts
for and reads the latitude of a location on earth in the
format:
integerDegrees
integerMinutes
doubleSeconds characterPosition
where characterPosition is either N,
n, S or s. If
the input is valid your program converts the input latitude to
decimal degrees where North latitudes are +ve, and South latitudes
are –ve.
26 13 15.272400 N
26.220909
50 11 55.024800 S
-50.198618
25 44 36.97 s
-25.743603
43 10 23.49 n
43.173192
:...
C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...
I need help programming this question using C language. This program uses input data entered in command line at the same time when the command or .exe file is entered. They are called command-line arguments. Because everything entered in command line is taken as a string, these arguments including the command itself or the .exe file name are stored in an array of char pointers, each pointer points to the first character of a string (i.e., argument). The inputs can...
Question 2 Use a switch statement to write the following program: Using C++ The program prompts the user for a letter grade (of type char). The list of valid letter grades is: A B C D E F The program should consider both lower and upper case The program will then display the following messages: For grade ‘A’: display “Excellent” For grade ‘B’: display “Good” For Grade ‘C’: display “Average” For grade ‘D’ or ‘E’: display “Below Average” For Grade...
Programming language is C++.
9. Write a program that reads digits and composes them into integers. For example, 123 is read as the characters 1, 2, and 3. The program should output 123 is 1 hundred and 2 tens and 3 ones. The number should be output as an int value Handle numbers with one, two, three, or four digits. Hint: To get the integer value 5 from the character '5' subtract '0' that is, '5'-'0'
Write a program that prompts the user to enter a character, an integer, and floating point number. After reading the input, the program should print out the values entered. Be sure to format the code correctly and include relevant comments. in c
CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from the given data file "data.txt" The program should be case insensitive and count the number of occurances of each character in the alphabet. It should print a histogram of the results as follows: A : B : C : * D : * E : * F : G : H : I : J : * K : L : M : N...
You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...
Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...