1 / 7

Case studies over control structures and iterative structures

Case studies over control structures and iterative structures. Instructor – Gokcen Cilingir Cpt S 121 ( July 6, 2011) Washington State University. Problem 1. Problem statement : Calculate number of digits in an integer. Prompt the user for an integer and output the number of digits

denzel
Télécharger la présentation

Case studies over control structures and iterative structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Case studies over control structures and iterative structures Instructor – GokcenCilingir Cpt S 121 (July 6, 2011) Washington State University

  2. Problem 1 • Problem statement: Calculate number of digits in an integer. Prompt the user for an integer and output the number of digits Sample I/O: Input: 123, Output: 3 Input: 123456, Output: 6 Input: 0, Output: 1

  3. Problem 1 – another related application • Problem statement: Print a given integer such that its digits are reversed. Sample I/O: Input: 123, Output: 321 Input: 123456, Output: 654321 Input: 0, Output: 0

  4. Problem 1 – another related application • Problem statement: Calculate the integer that has the reversed digits of a given integer. • Prompt the user for an integer and output the reversedInteger and reversedInteger *2 Sample I/O: Input: 123, Output: 321, 642 Input: 123456, Output: 654321, 1308642 Input: 0, Output: 0, 0

  5. Problem 2 • Problem statement: Write a program that experiments with the random number generation function rand() of C. Program should prompt user for sample size, and calculates the average of random numbers generated for the given sample size. • Generate random numbers between [0, 10] and observe that average will be closer to 5.0 when your sample size increases.

  6. Problem 3 • Problem statement: Write a program that reads and flattens a text file. • Assume file contains words (which are comprised by alphanumeric characters) separated by whitespace and punctuation characters. • Program should flatten the file, meaning should output the word list to an output file in the order of encounter, ignoring whitespace & punctuation, separating them by newline characters. • If time doesn’t allow to solve, it will be assigned as a lab problem!

  7. Problem 4 • Problem statement: Write a program to print a one month calendar. The user specifies the number of days in the month and the day of the week on which the month begins. • Sample execution: • If time doesn’t allow to solve, it will be assigned as a lab problem!

More Related