CSC270 Lab 10 2016

From dftwiki3
Jump to: navigation, search

--D. Thiebaut (talk) 19:17, 13 April 2016 (EDT)




This lab is to be completed after the lecture on C, with slides available here. Your report should contain the solution for each of the programs you are asked to write. Please create a text file using emacs, or an editor that can save raw text (no doc or trf output please). The reason is that I want to be able to compile your code and run it, so it has to be ASCII/text.



Please gather all your solutions in a giant program. This program, when run, should give the answers to all the problems listed in this lab.


Problem 1


Write a C program that prints all the letters of the alphabet (upper- or lowercase)

Problem 2


Write a C program that prints the first 10 Fibonacci terms (1, 1, 2, ... ) using a loop.

Problem 3


Write a C program that stores the first 10 Fibonacci terms in an array of 10 ints, using indexes, then prints the contents of the array.

Problem 4


Write a C program that stores the first 10 Fibonacci terms in an array of 10 ints, using pointers, then prints the contents of the array.

Problem 5


Write a C program that asks the user for a number of disks (use scanf()) and displays the moves requires to move that many disks in a game of Hanoi, where all the disks start on Peg A, and have to be moved to Peg C, using Peg B if necessary.

Problem 6


Write a C program that declares 2 int variables then prints them, then uses a swap function to swap their values. The program prints the final contents of the variables.

Problem 7


Write a C program that declares 2 string variables then prints them, then uses a swap function to swap their values. The program prints the final contents of the strings.


We stopped the lab here!



Problem 8 (Optional)


Write a C program that declares a string variable containing "Smith College" and replaces all the characters by 'A'.

Problem 9 (Optional)


Write a C program that declares a string variable containing "Smith College" and replaces all the characters by the first letters of the alphabet. Your program must use a loop!

Problem 10 (Optional)


Write a C program that declares two string variables, s1, and s2, containing your name and that of your teammate. For example "Mini Mouse" and "Donald Duck". Then make the program call a function to which it passes s1 and s2. The function processes the strings and returns them modified, such that that s1 will contain "Mini Duck" and s2 "Donald Mouse."

The main program then prints the modified strings.

You may use as many pointers or strings as you need.


Submission


Submit a text file with your program containing sections of code (functions?) that provide solutions to all the problems above, on Moodle. The deadline is 4/21/16 at 1:00 p.m.