0% found this document useful (0 votes)
46 views

Nama: Erika Roselyn Husen NIM: 2702259235

This document contains information about variable naming rules, differences between scanf and gets functions, conditional statements, loops, and validating string input length. It discusses that variable names cannot start with numbers or consist of more than one word, and that system can be used as a variable name. When using scanf to read input, only characters up to a space will be read, while gets will read the entire input. It also contains examples of if-else conditional statements and nested if statements.

Uploaded by

vincent 23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Nama: Erika Roselyn Husen NIM: 2702259235

This document contains information about variable naming rules, differences between scanf and gets functions, conditional statements, loops, and validating string input length. It discusses that variable names cannot start with numbers or consist of more than one word, and that system can be used as a variable name. When using scanf to read input, only characters up to a space will be read, while gets will read the entire input. It also contains examples of if-else conditional statements and nested if statements.

Uploaded by

vincent 23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Nama : Erika Roselyn Husen

NIM : 2702259235

1. Pseudo code :
Declare Integer productCode, quantity, price, totalPrice, finalTotal, i
For i = 0 < tambah
Input productCode
If productCode < 0000000000 Then
Input quantity
If quantity < 0 Then
Input price
Set totalPrice = quantity * price
If tambah Then
Return 0;
Else
finalTotal = finalTotal + totalPrice[i]
End If
End If
End If
End

Flowchart :

2. a. Variable name can be started with numbers [FALSE]


b. Variable name can not consist of more than a word [TRUE]
c. We can make variable with name of : system [TRUE]
3. scanf(“%s”, temp) and gets(temp) have different functions. When using scanf(“%s”,
temp) what is read will only be read up to a space, for example if you input “Good
Morning” then what will come out is “Good”, while gets will read until the end, for
example if you input "Good Morning” then the output is “Good Morning”
Nama : Erika Roselyn Husen
NIM : 2702259235

4. a s/d e :

f s/d j :

5.
Nama : Erika Roselyn Husen
NIM : 2702259235

6. The result of z = (x == 1) ? 5 : 7 if X is 0 → 7 , because 0 is not equal to 1.


Explanation : If the value of x is equal to 1 then it will be assigned the value 5. But in this
case X is 0 so the value is 7.

7. a.

b.
Nama : Erika Roselyn Husen
NIM : 2702259235

8. Nested selection occurs when the word IF appears more than once within IF statement.
9. Do while loop will execute the statement(s) at least once, then the condition is checked.
While loop checks the condition first and then executes the statement(s).
10.

11. a. Define a character array input of size 31 to allow for a maximum of 30 characters plus
the null terminator.
b. Use fgets to read the user’s input, and then we remove the newline character that fgets
might add to the end of the string.
c. Use the strlen function to calculate the length of the input string.
d. Check if the length of the input string is between 5 and 30 characters (inclusive). If it
is, we consider it valid; otherwise, it’s consideref invalid.

This code ensures that the input string length is within the specified range and provides
appropriate feedback to the user.

12.

13.
Nama : Erika Roselyn Husen
NIM : 2702259235

14.

You might also like