Starting from:

$25+

CH-230-A-Assignment 1 Solved

Programming in C and C++


•    The problems of this assignment must be solved in C or C++ (instruction in each problem).


#include <stdio.h>

int main() { double result; /∗ The result of our calculation ∗/ result = (3 + 1) / 5;

printf("The value of 4/5 is %lf\n", result); return 0;


#include <stdio.h>

int main() { int result; /∗ The result of our calculation ∗/ result = (2 + 7) ∗ 9 / 3;

printf("The result is %d\n"); return 0;


Read the error messages that the compiler produces and fix the errors such that your source code compiles successfully. Then fix the program to print the correct result. Explain within comments the reason of the errors and describe your fixes. include <stdio.h>

int main() { float result; /∗ The result of the division ∗/ int a = 5; int b = 13.5; result = a / b;

printf("The result is %d\n", result); return 0; }

1.   assigns 17 to x and 4 to y,

2.   prints the values of x and y,

3.   computes the sum of x and y and prints the result,

4.   computes the product of x and y and prints the result,

5.   computes the difference of x and y (x minus y) and prints the result,

6.   computes the division of x and y (x divided by y) and prints the result (the result should be a float),

7.   computes the remainder of the division of x and y in this order and prints the result.


 Testcase 1.4: inputTestcase 1.4: output
x=17 y=4 sum=21 product=68 difference=13 division=4.250000 remainder of division=1


1.   declares and initializes an integer variable x with 2138, and prints the value of x over 9 places,

2.   declares and initializes a float variable y with −52.358925, and prints the value of y over 11 places and with a floating point precision of 5,

3.   declares and initializes a char variable z with ’G’, and prints the character on the screen,

4.   declares and initializes a double variable u with 61.295339687, and prints the value of u with a floating point precision of 7.


 Testcase 1.5: inputTestcase 1.5: output
                                                                                                 x=               2138

y= -52.35892 z=G u=61.2953397

More products