Hello,
I was wondering if I could get assistance in resolving these questions for solutions. This is regarding my lab tomorrow morning at 8 Am.
I am not the best of coders, as this is my first time.. any help would be appreciated!
Thank you!
LAB #2
Purpose:
The purpose of this lab is to learn how to use
the Geany IDE (Integrated Development
Environment), to know about the basic steps
to write a C program, and to understand
common compiling and runtime errors.
Before the lab:
1. Read the tutorials and watch the videos on Geany (links in the left
margin).
During the lab:
PART I: PROGRAMMING EXERCISES
Exercise #1:
a. Using Geany, write the program "My first C program" as found on
the example programs website (ihypress.net) in the "Overview of
C" section.
b. Compile and build the program.
c. Run the program and see that it works properly.
d. Can you make the program write this also?
This
is
my
first
C
program.
Exercise #2:
a. Write a simple C program that will display the following pattern on
the screen:
X O X
X X O
O O X
Exercise #3:
a. Using Geany, write the following C program as is:
#include <stdio.h>
inx
main (void)
{
int a = 3; b = 4, e;
Double f = 4, c, d;
d = a + b;
c = a / (f - b);
printf (The value of d is %d"\n, d)
return (0);
}
b. Compile the program.
c. This program contains syntax errors. On a piece of paper, indicate
each one of them and make the appropriate corrections.
d. Write your answers in a text file.
e. Try to correct the errors. Compile and build the program with all
the corrections made.
f. Once the syntax errors have been corrected, there are two errors
that remains when you try to run it (one is called a runtime error
because you are trying to do something illegal, the other is a logic
error because you made a small mistake in the program). What
are they? Tell your TA or ask for hints!
g. Correct the errors and compile and run the program again. What
value of d is displayed?
Exercise #4:
a. Write and run in Geany a C program that does this: Ask the user
for a real number (like 316501.6735) and display the rounded
number to the nearest hundredth (ex: 316500), and the nearest
thousandth (ex: 316000). Can you do it with what you know at
this moment?
b. Can you display the rounded number to one decimal place? (ex:
316501.7). That one should be easy.
Exercise #5:
a. Find the formula of the ellipse on the internet and write and run
another C program that asks the user for both the long and short
radiuses and then calculates and displays the circumference of the
ellipse. You should be able to do that one without difficulty.
Exercise #6:
Answer these 10 questions by reading your notes, your textbook or by
trying with Geany:
1. What is the difference between char and Char?
2. What is displayed by printf ("%d", 3/4); ?
3. Is printf ("%f", 50); valid?
4. If you omit the ; at the end of a C statement, is it still working?
5. What is the difference between %f and %lf?
6. What happens when you attempt a division by zero in C?
7. Is the expression 35%15.3 valid?
8. Is there a difference between starting your program with main()
instead of int main (void)?
9. What happens if you try to display an integer between 0 and 255
with a %c placeholder?
10. Are the expressions 5/3, 5%3, 5.0/3 exactly the same?
Show your answers to your TA and write the answers in the same file
as exercise #3.
PART II: DISCOVERY ACTIVITIES
i. Using a text book or an Internet search (do not ask friends or
TA!), explain in one or two sentences the difference between the
printf and scanf statements in C.
ii. Using your text book or an Internet search (do not ask friends or
TA!), explain in one sentence or two the difference between
integer and double variables in C.
iii. Write the answers to the two discovery questions in the same file
as programming exercises 3 and 6.
PART III: LAB REPORT SUBMISSION
1. Submit the .c files for programming exercises 1, 2, 4, and 5.
2. Submit the text file containing the answers to programming
exercises 3 and 6 and the discovery activities.
3. Submit on D2L/Brightspace under Lab #2. Submissions are due at
the end of the lab session. You must submit your work before
leaving the lab.
After the lab:
1. Review the steps you took to perform the various operations in the
lab.
2. Try to install Geany and the C compiler (or Quincy or C-free) on
your home computer. Find the instructions in the Toolbox section
of the course website.
Homework:
• On paper (no computer needed), do the following programming
project (write the code by hand as you would on a test or an
exam).
• Show your homework to your lab assistant at the beginning of
next week's lab.
• If you wish, you may try your solution with the computer to see
if you got the correct solution (no need to show the computer
version).
• Homeworks are to be done individually and their
submission is optional.
Last modified: January 06 2022 10:24:02.