DOC PREVIEW
UConn CSE 2102 - Assignment #1

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 3100 Systems ProgrammingAssignment #1 Due: 09/13/2018For instructions on how to checkout the template code for the assignment and submit solutions using git, seeinstructions in lab0. Remember to pull, add, commit, and push. Do NOT add object file and executablesin your repo.Exercise 1. (50 points) Running average. Write a C program average.c that reads floating-pointnumbers (double) from the standard input and, after reading each number, prints the running total andaverage of the numbers that have been read so far. The program must terminate when there is an error orthe end of file (EOF) is detected at the standard input (e.g., when the user presses Ctrl-D).The block below shows a sample execution of the program in which the user provided input consists, inthis order, of numbers 1, 2, 1e10 (1010), and 0:$ ./average1Total=1.000000 Average=1.0000002Total=3.000000 Average=1.5000001e10Total=10000000003.000000 Average=3333333334.3333330Total=10000000003.000000 Average=2500000000.750000Notes. The loop needed to read the input is similar to that used in xorbit.c in Lab 1:while (scanf("%lf", &x) == 1) { // pay attention to %lf...};Here x is a double variable used to store the number read in each iteration. Printing the running total andaverage formatted as in the example above can be done usingprintf("Total=%f Average=%f\n", total, average); // pay attention to %fwhere total and average are variables of type double.Exercise 2. (50 points) Modular exponentiation. The following pseudocode shows how to computethe modular exponentiationnemod mwhere n, e, and m are integers such that n > 0, e > 0, and m > 1:r e s u l t = 1WHILE ( e > 0)IF e i s odd THENr e s u l t = ( r e s u l t ∗ n ) mod me = e / 2n = (n ∗ n ) mod mp r i n t r e s u l tWrite a C program powerMod.c that prompts the user for three integers n, e, and m and then prints tothe standard output the integer nemod m. You can assume that n > 0, e > 0, and m > 1 and all integersare less than 231− 1.The block below shows the expected execution of the program at the command line:1$ ./powerModPlease enter n, e, and m: 123 456 789123 ** 456 mod 789 = 699Specifically, the powerMod executable first prints the string “Please enter n, e, and m:” to prompt theuser to enter the numbers n, e, and m. The user types three integers (123, 456, and 789 in this example),separated by whitespaces. When the user hits the return key the program computes the desired value andproduces the output “123 ** 456 mod 789 = 699” on a single line.Write all of your code on your 3100 virtual machine in the hw1 folder found at the root of your Git repository.The provided Makefile defines rules for compiling your programs with make average and make powerMod,respectively. Both programs can be compiled with make all or just make, and all object files and executablescan be removed by executing make


View Full Document

UConn CSE 2102 - Assignment #1

Documents in this Course
Load more
Download Assignment #1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Assignment #1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assignment #1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?