CS 1160, Computing Fundamentals-Lab 2016/17: Exercise 1: Defining, Inputting and Printing Variables
CS 1160, Computing Fundamentals-Lab 2016/17: Exercise 1: Defining, Inputting and Printing Variables
23-27, 2016
Write a program that reads three integers (a, b, and c), computes the following formulas and stores the results in the
variables x1, x2 and prints the results of the program:
Exercise 5: Conditions
As reminder, in C we use the following operators to formulate conditions:
Operator Meaning example Operator Meaning example
== equal to x == 5 ! not !x
!= not equal to x != 5 !(x > 5)
< less x<5 && and x > 5 && y < 7
<= less or equal x <= 5 12 <= x && x <= 20
> greater x>5 || or x != 0 || y > 3
>= greater or equal x >= 5 x < 12 || x > 20
Verify your table entries by running the following program and comparing the output to what you have noted in the table:
#include <stdio.h>
int main() {
int i=1,j=2,k=3,m=2;
printf("%d\n",i==1);
printf("%d\n",j==3);
printf("%d\n",i>=1 && j<4);
printf("%d\n",m<=99 && k<m);
printf("%d\n",j>=i || k==m);
printf("%d\n",k+m<j || 3-j >=k);
printf("%d\n",!m);
printf("%d\n",!(j-m));
printf("%d\n",!(k>m));
printf("%d\n",!(j>k));
return 0;
}
CS 1160, Computing Fundamentals-Lab 2016/17 Week of Oct. 23-27, 2016
Please type in the following programs, compile them (if possible) and run them. Test all programs by entering 3, 0 and -5.
Make your notes next to the programs to remember your observations.
Program 1 Program 2
printf("Bye\n");
return 0;
}
Program 3 Program 4
Program 5 Program 6
1. Write a program that reads two numbers a and b. Print the maximum value of the two numbers.
2. Write a program that reads three input values. Output the maximum value of the three.
3. Write a C program that reads two float number and stores their values in variable x and y. the program then
computes the value (𝒙𝟐 − 𝒚𝟐 )⁄(𝒙 − 𝒚), stores the result in a float named z and prints the value of z. if the
computation division by zero, the program must avoid that by printing an error message and exiting before
computing the formula.
4. Use (if … else) to write a complete C application that asks the user to enter an integer Q Range ("deviation IQ") and
output the IQ Classification according to the following table:
120–129 Superior
90–109 Average
70–79 Borderline