You are on page 1of 10

TUGAS KELOMPOK

LAB 05

DASAR PEMROGRAMAN

DOSEN PENGAMPU:

Dewi Nasien S.T, M.Sc

DISUSUN OLEH:

Anandaku Aksana
1907155273
Farhan Maulana
1907113473
Salsabilla Azahra
1907124059

PROGRAM STUDI TEKNIK INFORMATIKA

FAKULTAS TEKNIK

UNIVERSITAS RIAU

2019
Excercise 1

1) Start

2) Declare variables a,b, and c

3) add formula b = 2+a

4) Add Formula b = 4(b)

5) Add formula b = a/3.14

6) Add formula a = b-8

7) Add value a=27

8) Desplay “L” as result with Variable C

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

printf("The value of c is %d, c)";  Error 2 and 3

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

printf(“The value of c is %d, c”);

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

Printf(“The value of c is %d”, c);

Excercise 3

The Output of the Program is

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;

printf ("n: %d", n);

printf ("\nm: %d", m);

x=10;

y=++x*2;

printf ("\nx: %d", x);

printf ("\ny: %d", y);

The result for the Source Code above is


n above is the result of the formula of m++*2, m as declared in the code is 10.
10 times Positive 2 equals 20. Y in printed result above is result from the code
++x*2. The inserted number in is 10, add 1 and then multiply by 2. Thus the
result is 22.

B)

//Program 5.4

int j=2, k=3;


double r=24.5, s=3.0, t1, t2;

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()

float item1, item2, item3, sum, subtotal, tax, total;

item1=12.96;

item2=24.95;

item3=6.95;

subtotal=(item1+item2+item3)/3;

tax=subtotal*0.06;

total=subtotal-tax;

printf("Value for item 1 is : %.2f", item1);

printf("\nValue for item 2 is : %.2f", item2);

printf("\nValue for item 3 is : %.2f", item3);

printf("\nSubtotal all three items is : %.2f", subtotal);


printf("\nTax Sales is : %.2f", tax);

printf("\nTotal payment is : %.2f", total);

Here is how it should look like

Excercise 6

1) Restaurant Bill Calculation

The source code is

#include <stdio.h>

int main()

{ float a,b,c,d;

printf("Cost of the food is RM 50.00");


a=50.00;

b=a*10/100;

c=b*5/100;

d=a+b+c;

printf("\nTax = %.2f", b);

printf("\nTip = %.2f", c);

printf("\nTotal Payment = %.2f", d);

The result of the code will be

2)

The Source Code is

#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;

printf("\nProfit of the Sold Circuit Board is RM %.2f", b);

printf("\nSelling Price of the Circuit Board is RM %.2f", c);

The printed result will be

You might also like