C代写/C++代写: CSC B09 lab 04 exercises week of 29 January 2018

C代写/C++代写:这是一个典型的C语言作业代写,涉及了基础的gcc编译方面的知识
Please begin by running “/cmsfaculty/ajr/b09/present”. This records your attendance and is required for you to get the marks for the lab.

Simple first task
Create a “hello, world” program in C (it just outputs “hello, world”) and compile it and make sure it runs properly.
Compile it with “gcc −Wall”. You should always compile with “gcc −Wall”.

Simple second task
Break your “hello, world” program into two .c files. One of them contains the main(), and the other one contains a function which does the actual printing. You would compile with a command like “gcc −Wall main.c hello.c”.
Make sure it compiles with no warnings or error messages, and performs exactly correctly (this is simple enough that you should be able to make it perfect).

Not quite as simple but still pretty simple third task, for submission
Consider a positive integer. If it is even, you divide it by two. If it is odd, you multiply it by three and add one. In either case, you loop around and keep processing until you get down to 1.
As it so happens, it’s an unsolved problem as to whether this algorithm terminates for all positive integers.

Write a program in C which takes a command-line argument which is a positive integer and performs this algorithm, outputting the new number each iteration, until it reaches 1.

Sample outputs: for an argument of 3, it should output 10, 5, 16, 8, 4, 2, 1. (Each number on a separate line, with no punctuation or extraneous whitespace, and your program may or may not print the final “1”.)
For an argument of 27, it produces 111 outputs (check this with “./a.out | wc −l”, although if you don’t print the final “1” the count should be 110).

We haven’t covered what you need to know in C to parse the command-line arguments yet, so please start with /cmsfaculty/ajr/b09/lab/04/starter.c which puts the numeric command-line argument into an int variable named ‘n’, objecting appropriately if the usage is incorrect or the number is not positive.

You can print the value of n with

printf(“%d\n”, n);
Call your file “3n1.c”.

As usual, your file must compile on the UTSC linux machines with “gcc −Wall” with no warning or error messages.

To submit
First of all, you must run “/cmsfaculty/ajr/b09/present”, during the tutorial time, on the console of a tutorial lab workstation.

Then, by noon on Monday February 5, you must submit your C file. Submit with the command

submit -c cscb09w18 -a lab04 3n1.c
You may still change your file and resubmit any time up to the due time, using “−f” as described towards the end of lab one; and you can use “submit −l” as also described in lab one.

发表评论

电子邮件地址不会被公开。 必填项已用*标注