labprog5-2010

labprog5-2010 - 16 17 18 19 20 21 22 23 24 25 26 27 28 29...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Swinburne University of Technology Faculty of Engineering and Industrial Sciences HES1300 Laboratory worksheet 5: To practice the use of control structure commands in C, students are asked to write a simple C program to print a calendar month. The program should ask the user to enter 2 integer numbers. The first is the number of days in the month and the second is the start day of the month (Sunday is 0, Monday 1, …Saturday 6). A typical result would look like: Sun Mon Tue Wed Thu Fri Sat --- --- --- --- --- --- --- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 --- --- --- --- --- --- --- A partial implementation of this program may look like: #include<stdio.h> int main() { int days, startDay, dayCount, weekDay; … printf("Sun Mon Tue Wed Thu Fri Sat\n"); … for(dayCount = 1; dayCount <= days; dayCount ++) { if(weekDay > 6) { printf("\n"); weekDay = 1; } else { weekDay ++; } printf("%3d ",dayCount); } printf("--- --- --- --- --- --- ---\n"); return(0); } After finishing the first part, try to rewrite your code using “while” and/or “do-while” commands....
View Full Document

This note was uploaded on 09/29/2010 for the course C++ c taught by Professor Lauren during the Three '10 term at Swinburne.

Ask a homework question - tutors are online