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

Practical 3 Code Sample UTAR Programming Concepts

The document contains 5 C programming questions and their solutions involving if/else statements. Question 1 determines admission fee based on age. Question 2 checks eligibility for sports based on ACT score, GPA, and high school rank. Question 3 performs math operations on integers and checks for division by zero. Question 4 calculates employee commission based on transaction code and retail price. Question 5 determines optimal paper packaging based on quantity purchased.

Uploaded by

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

Practical 3 Code Sample UTAR Programming Concepts

The document contains 5 C programming questions and their solutions involving if/else statements. Question 1 determines admission fee based on age. Question 2 checks eligibility for sports based on ACT score, GPA, and high school rank. Question 3 performs math operations on integers and checks for division by zero. Question 4 calculates employee commission based on transaction code and retail price. Question 5 determines optimal paper packaging based on quantity purchased.

Uploaded by

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

//Practical_3_Q1

#include <stdio.h>
int main()
{
int age;

printf("Please enter age: ");


scanf("%d", &age);

if (age > 55)


printf("Fee = RM 7 \n\n");
else
if (age >= 13 && age <= 55)
printf("Fee = RM 10 \n\n");
else
if (age >= 3 && age <= 12)
printf("Fee = RM 5 \n\n");
else
printf("Fee = FREE \n\n");

return 0;
}
-----------------------------------------------------------------------------------
--------------------------
//Practical_3_Q2
#include <stdio.h>
int main()
{
int req_mark, top_half;
float ACT, CGPA;

printf("Please enter ACT score: ");


scanf("%f", &ACT);

printf("Please enter CGPA: ");


scanf("%f", &CGPA);

printf("Did you graduate in the top half of your highschool class?


[yes=1/no=0]: ");
scanf("%d", &top_half);

req_mark = 0;

if (ACT >= 18)


{
req_mark++;
}
if (CGPA >= 2.0)
{
req_mark++;
}
if (top_half == "1")
{
req_mark++;
}

if (req_mark >= 2)
printf("\nELIGIBLE for sports \n");
else
printf("\nNOT ELIGIBLE for sports \n");

return 0;
}
-----------------------------------------------------------------------------------
-------------------------
//Practical_3_Q3
#include <stdio.h>
int main()
{
int int1, int2, sum, sub, mul;
float div;

printf("Please enter integer 1: ");


scanf("%d", &int1);

printf("Please enter integer 2: ");


scanf("%d", &int2);

sum = int1 + int2;


sub = int1 - int2;
mul = int1 * int2;

printf("\nThe summation is %d \n", sum);


printf("The subtraction is %d \n", sub);
printf("The multiplication is %d \n", mul);

if (int2 == 0)
printf("Quotient = Math error \n");

else
{
div = (float)int1 / int2;
printf("The quotient is %.2f \n\n", div);
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------
//Practical_3_Q4
#include <stdio.h>
int main()
{
char employee_no[10];
float retail_price, commission;
char transaction_code, S, M, L;

printf("Please enter employee number: ");


scanf("%s", &employee_no);
printf("Please enter retail_price: ");
scanf("%f", &retail_price);
printf("Please enter transaction code (S/M/L): ");
scanf(" %c", &transaction_code);

if (transaction_code == 'S' || transaction_code == 's')


commission = retail_price * 0.05;
else if (transaction_code == 'M' || transaction_code == 'm')
commission = retail_price * 0.07;
else if (transaction_code == 'L' || transaction_code == 'l')
commission = retail_price * 0.07;
else
{
commission = 0;
printf("INVALID CODE \n");
}

printf("Employee No: %s \n", employee_no);


printf("Retail price: RM %f.2 \n", retail_price);
printf("Commission: RM %f \n", commission);

return 0;
}
-----------------------------------------------------------------------------------
-------------------------
//Practical_3_Q5_V1
#include <stdio.h>
int main()
{
int paper_no, pack_no;

printf("Please enter amount of paper (sheets) you wish to purchase: ");


scanf("%d", &paper_no);

if (paper_no > 0 && paper_no <= 69)


printf("Purchase %d individual sheets \n\n", paper_no);
else if (paper_no >= 70 && paper_no <= 100)
printf("Purchase 1 pack of 100 sheets \n\n");
else if (paper_no >= 101 && paper_no <= 200)
printf("Purchase 2 pack of 100 sheets \n\n");
else if (paper_no >= 301 && paper_no <= 500)
printf("Purchase 1 pack of 500 sheets \n\n");
else if (paper_no >= 501 && paper_no <= 1000)
printf("Purchase 1 pack of 1000 sheets \n\n");
else if (paper_no > 1000 && paper_no % 1000 == 0)
{
pack_no = paper_no / 1000;
printf("Purchase %d packs of 1000 sheets \n\n", pack_no);
}
else
{
pack_no = paper_no / 1000 + 1;
printf("Purchase %d packs of 1000 sheets \n\n", pack_no);
}

return 0;
}
-----------------------------------------------------------------------------------
-------------------------

You might also like