Difference between revisions of "CSC270 Lab 10 2016"
(→Problem 10) |
(→Problem 10) |
||
Line 46: | Line 46: | ||
=Problem 10= | =Problem 10= | ||
<br /> | <br /> | ||
− | 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 | + | 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. | ||
<br /> | <br /> |
Revision as of 07:31, 14 April 2016
--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 use courier font for the code, to make it more readable!
Contents
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.
Problem 8
Write a C program that declares a string variable containing "Smith College" and replaces all the characters by 'A'.
Problem 9
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
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.