Description
Problem 1.1 Compute division (1 point)
Presence assignment, due by 11:00 AM today Graded manually
Language: C
Fix the program below such that it prints the correct result. Why is the result 0.000? Write your
answer and explanations within comments.
#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;
}
Problem 1.2 Wrong output (1 point)
Due by Monday, September 13th, 23:00 Graded manually
Language: C
Fix the program below such that it prints the correct value. Why does the program print “The
result is -1073745604”? (Values will vary). Write your answer and explanations within
comments.
#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;
}
Problem 1.3 A compile error (1 point)
Due by Monday, September 13th, 23:00 Graded manually
Language: C
You will get compiler errors, when you try to compile the example code given below.
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;
}
Problem 1.4 Simple arithmetics (1 point)
Due by Monday, September 13th, 23:00 Graded automatically with testcases only
Language: C
Write a program which does the following:
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.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 1.4: input Testcase 1.4: output
x=17
y=4
sum=21
product=68
difference=13
division=4.250000
remainder of division=1
Problem 1.5 Using printf for multiple data types and conversions (1 point)
Due by Monday, September 13th, 23:00 Graded automatically with testcases only
Language: C
Write a program which:
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.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 1.5: input Testcase 1.5: output
x= 2138
y= -52.35892
z=G
u=61.2953397
Problem 1.6 Printing a char as character and as decimal value (1 point)
Due by Monday, September 13th, 23:00 Graded manually
Language: C
Write a program which declares and initializes a char variable c with ’F’ and prints on the screen
the third character (within the alphabet) after c as a character and as the corresponding ASCII
code using only arithmetic operations.
How to submit your solutions
• Your source code should be properly indented and compile with gcc or g++ depending on the problem without any errors or warnings (You can use gcc -Wall -o program program.c or g++
-Wall -o program program.cpp). Insert suitable comments (not on every line . . . ) to explain
what your program does.
• Name the programs according to the suggested filenames (they should match the description of the
problem) in Grader.
Each program must include a comment on the top like the following:
/*
CH-230-A
a1 p1.[c or cpp or h]
Firstname Lastname
myemail@jacobs-university.de
*/
• You have to submit your solutions via Grader at
https://grader.eecs.jacobs-university.de.
If there are problems (but only then) you can submit the programs by sending mail to
k.lipskoch@jacobs-university.de with a subject line that begins with CH-230-A.
It is important that you do begin your subject with the coursenumber, otherwise I might have
problems to identify your submission.
• Note, that after the deadline it will not be possible to submit any solutions. It is useless to send late
solutions by mail, because they will not be accepted.
This assignment is due by Monday, September 13th, 23:00.