0% found this document useful (0 votes)
2 views6 pages

BASIC C Answer

The document includes a flowchart and C programming code for taking temperature based on the age of a child in months, recommending different methods accordingly. It also contains examples of a for loop to calculate the total price of books and a switch case structure to perform operations based on user input. Additionally, there are outputs provided for the examples, demonstrating the functionality of the code.

Uploaded by

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

BASIC C Answer

The document includes a flowchart and C programming code for taking temperature based on the age of a child in months, recommending different methods accordingly. It also contains examples of a for loop to calculate the total price of books and a switch case structure to perform operations based on user input. Additionally, there are outputs provided for the examples, demonstrating the functionality of the code.

Uploaded by

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

1(a)(i) Flowchart for Taking Temperature:

ii) Program

#include <stdio.h>

int main() {
int age_months;

printf("Enter age in months: ");


scanf("%d", &age_months);

if (age_months <= 3) {
printf("Recommended method: Rectal\n");
}
else if (age_months > 3 && age_months <= 36) {
printf("Recommended method: Rectal, Ear or Armpit\n");
}
else if (age_months > 36 && age_months <= 60) {
printf("Recommended method: Oral, Rectal or Armpit\n");
}
else {
printf("Recommended method: Oral, Ear or Armpit\n");
}

return 0;
}
2(a)(i) OUTPUT

13
10

ii) OUTPUT

13 4

B) Convert for loop

#include <stdio.h>

void main() {
float harga, jumlah = 0;

for (int data = 0; data <= 10; data++) {


printf("Masukkan harga buku = ");
scanf("%f", &harga);
jumlah += harga;
}

printf("Jumlah harga buku = %2.1f", jumlah);


}
C) Switch case

#include <stdio.h>

void main() {
int digit, a, b, c, k, i = 4, j = 25;
k = 1;

printf("Please enter digit (between 1 to 2 only): ");


scanf("%d", &digit);

switch(digit) {
case 1:
a = i++;
b = j--;
c = i - j;
k = a + b + c;
printf("%d", k);
break;

case 2:
a = --i;
b = ++j;
c = j - i;
k = a + b + c;
printf("%d", k);
break;

default:
printf("Wrong selection!");
}
}
D) Flowchart

You might also like