Professional Documents
Culture Documents
LAB 05
DASAR PEMROGRAMAN
DOSEN PENGAMPU:
DISUSUN OLEH:
Anandaku Aksana
1907155273
Farhan Maulana
1907113473
Salsabilla Azahra
1907124059
FAKULTAS TEKNIK
UNIVERSITAS RIAU
2019
Excercise 1
1) Start
9) End
Excercise 2
//Program 5.1
#include <stdio.h>
#include <conio.h>
int main()
int a,b;
a=3;
b=4;
c=a+b; Error 1
getch();
return 0;
Error 1, Variable C was not declared in the scope. Means the variable wasn’t
included in the previous code. The correct input code is
int a,b,c;
Error 2, Expected ‘)’ before ‘;’, means the ‘)’ symbol has to be placed before ‘;’
symbol. The correct input is
Error 3, Although the input is already correct, however the result will not be as
expected. The ‘, c’ variable has to be placed outside the ‘ “ ‘ symbol. In order
for the program to correctly executed, the correct input should be
Excercise 3
The program above is a program for calculating the area of a rectangle. The
calculation use the formula “length x width”. However, we input the code
“length * width” to calculate the result. In the program, the inserted length is
12, and the width is 13. Therefore, the result for 12 x 13 is 156.
Now, we change the length to 12.12 and the width 13.12. The result will looks
like below:
As we can see, the result is 0.000 which means it’s an error because the
calculation for 12.12 x 13.12 is not 0.00000. Why the result is like that because
decimal numbers use float variables, not int type of variables. The function to
declare the result is currently %d, which only works for int type of variable. To
show the result of float type of variables, we have to use %f as a result
declaration. Currently, we’re using int on the source code above, now let’s
change the int into float and the %d to %f, let’s see the result.
As seen above, the result is correct. The correct answer for 12.12 x 13.12is
159.014404. Thus, the output is now correct.
Exercise 4
A)
//Program 5.3
int n, m, x, y;
m=10;
n=m++*2;
x=10;
y=++x*2;
B)
//Program 5.4
t1*=r+s;
t2=r-s*3%(2+j)/k;
The result will be an error. The cause is that in the formula, the “%” symbol on
the 4th line is not a valid calculation symbol for calculating numbers on the
formula. A “%” sign is not an operating symbol. Therefore, the calculation
cannot proceed and the result will be error.
Excercise 5
SourceCode
#include <stdio.h>
int main()
item1=12.96;
item2=24.95;
item3=6.95;
subtotal=(item1+item2+item3)/3;
tax=subtotal*0.06;
total=subtotal-tax;
Excercise 6
#include <stdio.h>
int main()
{ float a,b,c,d;
b=a*10/100;
c=b*5/100;
d=a+b+c;
2)
#include <stdio.h>
int main()
{ float a,b,c;
printf("Cost of the Circuit Board is RM 12.67");
a=12.67;
b=a*40/100;
c=a+b;