Lec 7 - Additional Exercises
Lec 7 - Additional Exercises
Lec 7 - Additional Exercises
SECTION/SCHEDULE:________________________________________ SCORE:_____________
Mp2
Mp3
Mp4
Mp5
Mp6
/***********************************************************************
This program illustrates the use of various operators in C.
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;
}
/***************************************************************************
This program illustrates the use of the if-statement and random number generation using
srand(), time() and rand()
#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();
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.
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