EPROG/LA
(COMPUTER FUNDAMENTALS AND PROGRAMMING FOR
ENGINEERING STUDENTS)
EXERCISE
4
Operators and expressions,
Input/Output Operations
Name of Student Name of Professor
Uykhilam, Immanuel John Prof. Maghanoy
Data Performed Date Submitted
5/2/2019 5/2/2019
I. Objectives:
At the end of the experiment students must be able to:
a.) understand the input-process-output
b.) understand how operators are used
c.) identify the different operators
d.) construct a program that asks inputs from user, uses different operators and performs
calculations with the use of different operators.
e.) appreciate the concept behind operators.
II. BACKGROUND INFORMATION
Use unary and arithmetic operators for basic mathematical operations
• Use string operator to concatenate strings
• Use relational operators to compare objects
• Use logical operators to compare boolean values
• Use assignment operators to assign values to variables
III. PROCEDURE:
1. Getting the average of three numbers. Create a program that outputs the average of three numbers. Let
the values of the three numbers be, 10, 20 and 45. The expected screen output is,
number 1 = 10
number 2 = 20
number 3 = 45
Average is = 25
#include<stdio.h>
int main()
{
int num1, num2, num3, ave;
num1 = 10;
num2 = 20;
num3 = 45;
printf("The first number is 10: \n");
printf("The second number is 20: \n");
printf("The third number is 45: \n");
ave = (num1+num2+num3)/3;
printf("The Average is: %d", ave);
getchar();
}
2. The user will input a Philippine amount, then the said amount will be converted to different currencies
namely: US Dollar, Euro, Yuan, Koruna, Krone, Sheqel and Dinar
Sample run:
Enter Philippine peso: 43.33089
The amount's equivalent to:
US Dollar is : 1.000
Euro : 0.734719
Yuan : 6.346934
Koruna : 18.77263
Krone : 5.449007
Sheqel : 3.726334
Dinar : 0.274588
Suppose, 1.000 US Dollar is equivalent to Php. 43.33089, 0.734719Euro, 6.346934 Yuan, 18.77263
Koruna, 5.449007 Krone, 3.726334 Sheqel, and 0.274588 Dinar.
#include<stdio.h>
int main()
{
float peso, dollar, euro, yuan, kor, krone, sheqel, dinar;
printf("Enter Philippine PEso: \n");
scanf("%f",&peso);
dollar = peso/43.33089;
euro = peso*0.016956;
yuan = peso*0.146476;
kor = peso*0.43324;
krone = peso*0.1257534 ;
sheqel = peso*0.85997;
dinar = peso*0.006337;
printf("The Amount's equivalent to: \n");
printf("US Dollar is: %f \n",dollar);
printf("Euro is: %f \n",euro);
printf("Yuan is: %f \n",yuan);
printf("Koruna is: %f \n",kor);
printf("Krone is: %f \n",krone);
printf("Sheqel is: %f \n",sheqel);
printf("Dinar is: %f \n",dinar);
getchar();
}
4. Create a program that will convert:
6.1 Degree Fahrenheit to degree celsius
#include <stdio.h>
int main()
{
float c, f;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
c = (f - 32) * 5 / 9;
printf(" %f Fahrenheit = %f Celsius", f, c);
return 0;
}
V. QUESTION AND ANSWER:
1. Which of the four arithmetic operators can operate on string as well as numeric operands?
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
2. Assuming total is a variable, how else could you express in code total = total +2?
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
VI. Assessment
Department Computer Science Department
Subject Code EPROG/EPROGLA
Description Computer fundamentals and programming for
engineering students
Term/Academic Year 1
Topic Introduction to C programming
Basic Input Output operation
Operators and expressions
Lab Activity No 4
Lab Activity Operators and expressions,
Input/Output Operations
CLO
Note: The following rubrics/metrics will be used to grade students’ output in the lab
exercise 4.
Criteria Descriptions Points
Task no 1 The variables and the corresponding 10
values are properly assigned and used
in the program.
Task no 2 The program should get the average of 10
3 numbers. The values for the numbers
given are used, and the output on the
screen should be the same as stated on
the question.
Task no 3 Uses the ?: operator to get the greatest 10
value among the 3 numbers
dynamically, meaning the numbers
should come from the user and it could
be any random number
Task no 4 The expressions given should be 10
converted to an expression with
parenthesis based on their precedence
Task no 5 The program should convert a 10
Philippine currency to different
currencies
Task no 6 The program should convert the 10
different type of measurement to
another type
Task no 7 The program should encorporate all of 10
the given operators.
Error in the program The program made is free of errors and 15
bugs.
Output The output of the program is correct 15
and solved based on the problem
stated.
Total 100%
V. REFERENCES