Question

In: Computer Science

(Using pseucode ) 2. Compute and display the value of X divided by Y if the...

(Using pseucode )
2. Compute and display the value of X divided by Y if the value of Y is not zero. If Y does have the value 0 then display a message
saying, “Unable to perform the division”

4. Write an algorithm that inputs four exam scores corresponding to scores received on 3 semester tests and a Final Exam. Your algorithm should compute and display the average of all four tests weighing the final exam twice as heavily as a regular test.

5. Modify the test averaging algorithm you wrote in problem 4 above so that it reads in a total of 14 regular test scores plus a final exam score, which counts twice as much as a regular test. Use a loop to input and sum the scores.

Solutions

Expert Solution

/*----------------------------------------------------------------------\
|psuedo code:                               |
|   sem := 50 (max marks of sem)                   |
|   final := 100 (max marks of final twice of semester)       |
|                                   |
|   i := 0                               |
|   while i<15:                           |
|       testscore[i] := get the value of test score       |
|       i := i + 1                       |
|                                   |
|   loop over i=0 for 15 times to add score:           |
|       total := total + testscore[i]               |
|                                   |
|   avg := total / 15                       |
|                                   |
|   return avg                           |
|----------------------------------------------------------------------*/

#include<stdio.h>

int main(){
   int i=0, j=0;
   float maxsem = 50;
   float score[15], avg, total=0;

   while(i<15){
       printf("Enter test score for test %d: ", i+1);
       scanf("%f", &score[i]);
       if(score[i]>maxsem && i<14){
           printf("Max. score for sememster test is 50.\n");
       }
       else if(score[i]>(2*maxsem) && i==14){
           printf("Max. score for final test is 100.\n");
       }
       i++;
   }

   while(j<15){
       total += score[j];
       j++;
   }

   avg = total/i;
   printf("Average score: %.2f\n", avg);

return 0;
}


/*--------------------------------------------------------------\
|psuedo code:                           |
|   x := get the value of x                   |
|   y := get the value of y                   |
|                               |
|   if y == 0 :                       |
|       display("Unable to perfomr the division")   |
|   else :                           |
|       z := x/y                   |
|       display("Result: z")               |
|                               |
|--------------------------------------------------------------*/

#include<stdio.h>

int main(){
   float x, y, z;
   printf("Enter the value of x: \n");
   scanf("%f", &x);
   printf("Enter the value of y: \n");
   scanf("%f", &y);

   if (y == 0){//checking the value of Y equals to 0 or not
       printf("Unable to perform the division.\n");//display err msg
   }
   else{
       z = x/y;//performing division
       printf("X divided by Y equals : %f\n", z);//display result
   }

return 0;
}


Related Solutions

For the differential equation (2 -x^4)y" + (2*x -4)y' + (2*x^2)y=0. Compute the recursion formula for...
For the differential equation (2 -x^4)y" + (2*x -4)y' + (2*x^2)y=0. Compute the recursion formula for the coefficients of the power series solution centered at x(0)=0 and use it to compute the first three nonzero terms of the solution with y(0)= 12 , y'(0) =0
Find the average value of f(x, y) = e −(x 2+y 2 ) on x 2...
Find the average value of f(x, y) = e −(x 2+y 2 ) on x 2 + y 2 ≤ π
x^2*y''+x*y'+(x^2-1)y=0 what is the solution by using Frobenius method
x^2*y''+x*y'+(x^2-1)y=0 what is the solution by using Frobenius method
Compute the double integral A = 2 (x + y)dxdy y Note that the region of integration lies to the right of the line y = x.
Compute the double integral Note that the region of integration lies to the right of the line y = x. Use this fact and a MATLAB relational operator to eliminate values for which y > x.
For the X,Y data below, compute:
For the X,Y data below, compute: X Y 2 5 4 6 4 7 5 11 6 12 (a) the correlation coefficient and determine if it is significantly different from zero. (b) find the regression line. c) interpret the coefficient of the regression line d) at 5% test if the Y is related to X e) find the coefficient of determination and interpret this coefficient. f) predict the value of average Y if the average of X is13 g) at...
11. Solve numerically the following Boundary Value Problem. X2Y” – X(X+2)Y’ + (X+2)Y = 0 Y(1)...
11. Solve numerically the following Boundary Value Problem. X2Y” – X(X+2)Y’ + (X+2)Y = 0 Y(1) = e and Y(2) = 2e2 The value of e = 2.71828
Find the absolute maximum value and the absolute minimum value of the function f(x,y) = (1+x^2)(1−y^2)...
Find the absolute maximum value and the absolute minimum value of the function f(x,y) = (1+x^2)(1−y^2) on the disk D = {(x,y) | x2+y2⩽1}?
using matlab, compute and plot y [n] = x [n]* h [n], where a. x [n]...
using matlab, compute and plot y [n] = x [n]* h [n], where a. x [n] = h [n] = a^n (0 <=n <=40) & a = 0.5 b. x [n] = cos [n]; h [n] = u [n]; n = 0:4:360 c. x [n] = sin [n] ; h [n] = a^n; n:4:360; a = 0.9
Given function f(x,y,z)=x^(2)+2*y^(2)+z^(2), subject to two constraints x+y+z=6 and x-2*y+z=0. find the extreme value of f(x,y,z)...
Given function f(x,y,z)=x^(2)+2*y^(2)+z^(2), subject to two constraints x+y+z=6 and x-2*y+z=0. find the extreme value of f(x,y,z) and determine whether it is maximum of minimum.
Let u(x, y) = x^3 + kxy^2 + y. (a) Determine the value of k such...
Let u(x, y) = x^3 + kxy^2 + y. (a) Determine the value of k such that u is an harmonic function. (b) Find the harmonic conjugate v of u. (c) Obtain the expression of f = u + iv in terms of z = x + iy
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT