Lec 7 - Additional Exercises

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

LBYEC71

NAME: ___________________________________________________ DATE:______________

SECTION/SCHEDULE:________________________________________ SCORE:_____________

DATA & RESULTS:

Procedure No. OBSERVATION/OUTPUT

Part 1 1. Provide your observations and the output on a separate sheet

Part 2 1. Provide your observations and the output on a separate sheet

For Teacher’s Evaluation


Mp1

Mp2

Mp3

Mp4

Mp5

Mp6

Lab Manual courtesy of Mr. J. Catalan & Tony Gonzales 1


Objective: In this exercise, the student will:
1. learn how to use C operators
2. learn how to use the if- and if-else statements
3. learn how to use the built-in trigonometric functions in C
4. learn how to use the delay() function
5. create program using conditional statements

Part 1. Use of operator

1. Type, compiler, run and analyze the following program:

/***********************************************************************
This program illustrates the use of various operators in C.

Program written by J. Catalan.


***********************************************************************/
#include <stdio.h>
#include <conio.h>

int x1 = 2, y=15;

main()
{
float x=1.3;

clrscr();
printf("1> ++x1 is %i \n", ++x1);
printf("2> x1 is %i \n", x1);
printf("3> x1++ %i \n", x1++);
printf("4> x1 is %i \n", x1);
printf("5> --y is %i \n", --y);
printf("6> y is %i \n", y);
printf("7> y-- is %i \n", y--);
printf("8> y is %i \n", y);
printf("9> (69 %% 6) is %i \n", (69 % 6));
printf("10> 1<2 is %i \n", 1<2);
printf("11> x!=y is %i \n", x!=y);
printf("12> (x!=y)>(1<2) is %i \n", (x!=y)>(1<2));
printf("13> 1&&1 is %i \n", 1&&1); /* displays 1 */
printf("14> 1&&0 is %i \n", 1&&0); /* displays 0 */
printf("16> (1>2)||(1==2) is %i \n", (1>2)||(1==2)); /* displays 0 */
printf("17> !(1<2)&&(1.2) %i \n", !(1<2)&&(1.2)); /* displays 0 */
return 0;
}

Lab Manual courtesy of Mr. J. Catalan & Tony Gonzales 2


Part 2. Use of if- and if-else statements

1. Type, compile, run and analyze the following program:

/***************************************************************************
This program illustrates the use of the if-statement and random number generation using
srand(), time() and rand()

Written by J. Catalan. All rights reserved.


***************************************************************************/

#include <stdio.h>
#include <conio.h>
#include <stdlib.h> /* required for srand(), rand() */
#include <time.h> /* required for time() */

void main(void)
{
int x1,x2;
time_t t;

clrscr();
srand(((unsigned) time(&t))*10000); /* this initiates the random number generator. */
printf("this program generates a random number between 0 and %li\n",RAND_MAX);
printf("and determines using the if statement if the random number is\n");
printf("is higher or lower than %i\n\n", (int) RAND_MAX/5);
printf("Press any key to generate a random number..");
getch();

x1 = rand(); /* this generates the random number */

printf("\n\nThe number is %i.\n", x1);


x2 = (int) RAND_MAX/5; /* (int) is a typecast */
printf("\nConditional output 1:");
if (x1<x2) printf("It is lower than %i!\n",x2);
if (x1>x2) printf("It is higher than %i!\n",x2);
if (x1==x2) printf("It is equal to %i!\n",x2);

printf("\nConditional output 2:");


if (x1<x2) printf("It is lower than %i!\n",x2);
else if (x1>x2) printf("It is higher than %i!\n",x2);
else printf("It is equal to %i!\n",x2);
getch();
return;

Lab Manual courtesy of Mr. J. Catalan & Tony Gonzales 3


Machine Problems:

1. A program that converts the temperature from Fahrenheit to Celsius.


5
C= (° F − 32)
9
2. Accepts 2 integers and displays their sum, diff, prod, quotient, average, bitwise AND
(&), bitwise OR ( | ) and the one's complement ( unary ~ ).

3. Displays the area of a triangle given 3 sides by using heron's formula. Invalid sides
are not accepted.

4. A program that accepts Q1, Q2, Pr1, Pr2, TE, and FE and displays the final grade
including the remarks.

PERCENTAGE Input Score


Range

QUIZZES, Q1 and Q2 20 % 0 to 100


MACHINE PROBLEM AVE. 20 % 0 to 100
PRACTICAL EXAM, Pr1, Pr2 20 % 0 to 100
FINAL EXAM 35 % 0 to 100
TEACHER’S EVALUATION 5% 0 to 5

Score Final Remarks Score Final Remarks


Grade Grade
Below 65 0.0 Fail 80 – 84 2.5 Satisfactory
65 – 69 1.0 Poor 85 – 89 3.0 Very Satisfactory
70 – 74 1.5 Fair 90 – 94 3.5 Excellent
75 – 79 2.0 Moderate 95 – 100 4.0 Outstanding

5. A program that accepts integers ranging from 1 to 20 and displays its Roman numeral
equivalent, using switch statement.

6. A program that takes X – Y coordinates of a point in the Cartesian plane and prints a
message telling where the point lies.

(a) Origin
(b) x or y axis
(c) Quadrants I, II III or IV

Lab Manual courtesy of Mr. J. Catalan & Tony Gonzales 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy