Difference between revisions of "CSC270 Lab 10 2016"
(Created page with "--~~~~ ---- <br /> <br /> <bluebox> This lab is to be completed after the lecture on C, with slides available [http://www.science.smith.edu/dftwiki/media/CSC270_2016Notes11.pd...") |
(→Problem 1) |
||
Line 10: | Line 10: | ||
=Problem 1= | =Problem 1= | ||
<br /> | <br /> | ||
+ | Write a C program that prints all the letters of the alphabet (upper- or lowercase) | ||
<br /> | <br /> | ||
+ | =Problem 2= | ||
+ | <br /> | ||
+ | Write a C program that prints the first 10 Fibonacci terms (1, 1, 2, ... ) using a loop. | ||
+ | <br /> | ||
+ | =Problem 3= | ||
+ | <br /> | ||
+ | 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. | ||
+ | <br /> | ||
+ | =Problem 4= | ||
+ | <br /> | ||
+ | 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. | ||
+ | <br /> | ||
+ | =Problem 5= | ||
+ | <br /> | ||
+ | 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. | ||
+ | <br /> | ||
+ | =Problem 6= | ||
+ | <br /> | ||
+ | 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. | ||
+ | <br /> | ||
+ | =Problem 7= | ||
+ | <br /> | ||
+ | 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. | ||
+ | <br /> | ||
+ | =Problem 8= | ||
+ | <br /> | ||
+ | Write a C program that declares a string variable containing "Smith College" and replaces all the characters by 'A'. | ||
+ | <br /> | ||
+ | =Problem 9= | ||
+ | <br /> | ||
+ | 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! | ||
+ | <br /> | ||
+ | =Problem 10= | ||
+ | <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 process the string so that s1 contains "Mini Duck" and s2 contains "Donald Mouse" at the end. | ||
+ | |||
+ | <br /> | ||
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 19:02, 13 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 process the string so that s1 contains "Mini Duck" and s2 contains "Donald Mouse" at the end.